我在使用SQL CE选择所有计数值列表到表时遇到问题。
SELECT Time AS Hour,Cast (COUNT(ReceivedTime)*1.0/(10)as decimal(16,2)) AS HourlyTotal
FROM tblTime
LEFT OUTER JOIN tblMessageReceived ON Time = ReceivedTime
WHERE ReceivedDateTime >= '2016-01-01' AND ReceivedDateTime <= '2016-07-07'
GROUP BY Time
但它只选择非零计数。作为下面的结果表。
在这里,我想用0计数值选择所有小时时间。
答案 0 :(得分:1)
您的WHERE
条款有效地将您的LEFT JOIN
变为INNER JOIN
。解决方案是将它们放在ON
子句中:
SELECT
t.Time AS Hour,
CAST(COUNT(t.ReceivedTime)*1.0/(10) AS DECIMAL(16, 2)) AS HourlyTotal
FROM tblTime t
LEFT OUTER JOIN tblMessageReceived tmr
ON t.Time = tmr.ReceivedTime
AND tmr.ReceivedDateTime >= '2016-01-01'
AND tmr.ReceivedDateTime <= '2016-07-07'
GROUP BY t.Time
注意: