0

我有一张桌子

ID | product | cuid | file     | created    | start_date | cancelled  | brid   | price
123| prod3   | 1234 | filename | 2012-09-19 | 2012-09-19 | 2012-09-19 | broker | 20
124| prod1   | 1234 | filename | 2012-09-19 | 2012-09-19 | 0000-00-00 | broker | 10
125| prod1   | 1234 | filename | 2012-09-19 | 2012-09-19 | 0000-00-00 | broker | 10
126| prod3   | 1234 | filename | 2012-09-19 | 2012-09-19 | 0000-00-00 | broker | 20

created、start_date 和 cancelled 都是 DateTime 列。

我正在运行查询以计算出每种产品的数量、每种产品的总成本和所有产品的总价格,使用:

SELECT 
      count(product) as amount,
      product, 
      sum(price) AS price 
FROM `products` 
WHERE 
      brid = 'broker' 
AND 
      cancelled is null 
GROUP BY product 
WITH ROLLUP

这给了我

amount     | product            | price

2          | PROD1              | 20
2          | PROD3              | 40
4          | NULL               | 60

PROD3 产品之一的取消列中有日期,因此结果应为

1          | PROD3              | 20

添加和删​​除“取消为空”似乎对结果没有任何影响。还尝试了'cancelled =“0000-00-00 00:00:00”'这并没有影响结果......

任何想法我如何将其限制为仅尚未取消的产品?

请提供任何帮助!

4

1 回答 1

0

你应该把AND cancelled IS NOT NULL

于 2012-09-21T10:32:24.637 回答