我正在尝试进行SQL调用,避免使用小计为$ 0的订单。我无法省略小于0.00的订单。
我的SQL电话:
SELECT Orders_Products.productID,
Orders_Products.QtyOrdered,
Orders.DateCreated,
Orders_Products.Subtotal,
SUM(Orders_Products.Subtotal) as Revenue
FROM `Orders_Products`
INNER JOIN Orders
ON Orders_Products.OrderID = Orders.OrderID
WHERE ProductID <= 21
AND ProductID >= 19
OR ProductID = 41
AND Orders_Products.Subtotal <> 0.00
AND MONTH(Orders.DateCreated) = MONTH(CURDATE())
AND Year(Orders.DateCreated) = YEAR(CURDATE())
GROUP BY DateCreated
ORDER BY `Orders`.`DateCreated` DESC
这就是我遇到问题的地方(仍显示小计0.00的订单):
AND Orders_Products.Subtotal <> 0.00
我也试过
AND Orders_Products.Subtotal != 0.00
AND Orders_Products.Subtotal <> 0
AND Orders_Products.Subtotal <> "0.00"
但我的输出仍包含小计0.00的订单项:
答案 0 :(得分:3)
我猜括号有问题。 它看起来应该作为一个条件收集:
(ProductID <= 21 AND ProductID >= 19 OR ProductID = 41)