0

我正在使用它,但没有找到任何值...我认为这个查询有错误...实际上我想知道如何在 sqlite 中使用多个表来使用多个求和、乘法等

SELECT 
  dhid, dprice, dname,
  SUM(dmilk) AS totalmilk,
  dprice*SUM(dmilk) AS totalmilkamt,
  SUM(ghee) AS toalghee,
  SUM(ghee*gheeprice) AS totalgheeamt,
  SUM(ghee*gheeprice)+dprice*SUM(dmilk)  AS totals,
  SUM(cashamount)   AS totalcash,
  SUM(ghee*gheeprice)+dprice*SUM(dmilk)-SUM(cashamount) AS balance 
FROM
  (         SELECT *
              FROM costumer
   LEFT OUTER JOIN salesdata
                ON costumer.dhid=salesdata.ddhid
   LEFT OUTER JOIN cashdata
                ON salesdata.ddhid=cashdata.uid
               AND utype='costumer')
   WHERE dmonth='$mikdatem'
     AND dyear='$mikdatey' 
     AND dhid='$dhid' 
ORDER BY dhid ASC
4

1 回答 1

0

您在上面的选择对我们没有帮助,因为我们没有基础数据来了解您想要做什么。

所以一般的答案是这样的:当使用分组函数(SUM/COUNT ...)时,您总是需要某种形式的“GROUP BY”来处理这些分组函数中未使用的列。

给出的例子:

SELECT name, sum(dmilk)
FROM milk_entry
GROUP BY name
于 2012-09-05T12:03:27.760 回答