在下面的查詢我要永遠顯示行即使SUM結果爲0濾鏡通過
沒有正常工作的WHERE子句,但是當我想在日期之間過濾,不會返回任何結果。什麼細節失敗?
SELECT tc.cars,
COALESCE(SUM(ts.sales),0) AS cars_sales
FROM tbl_cars tc
LEFT JOIN tbl_sales ts ON tc.id_cars = ts.id_cars
WHERE tc.recDate BETWEEN '2017-04-01' AND DATE_ADD('2017-05-01' , INTERVAL 1 DAY)
GROUP BY tc.cars
ORDER BY tc.cars;
SQLFiddle:http://www.sqlfiddle.com/#!9/425e6d/1/0
四月到五月間你沒有車。 http://www.sqlfiddle.com/#!9/425e6d/11 – chris85
@ chris85,「即使SUM結果爲0,我也要始終顯示行」。 – ishegg
...或者即使沒有行返回應該有'0'? – chris85