我想要無NetSales within 180日 to 90 日出零...
想請問如果沒有Sales within that period, how do I get a 0 for that customer?- select c.CustomerID, o.PurchaseDateTime, IFNULL(sum(round(od.NetSales,2)),0) as NetSales180
- from customers AS c LEFT JOIN orders AS o
- ON (c.CustomerID = o.CustomerID)
- LEFT JOIN order_details AS od ON (o.OrderID = od.OrderID)
- where DATE(o.PurchaseDateTime) BETWEEN CURDATE() - INTERVAL 180 DAY AND CURDATE() - INTERVAL 90 DAY
-
- group by c.CustomerID
複製代碼 Customer ID NetSales180
1 0
2 3000.0
3 0
現在我一條row 都無....
THX |
|
|