आपको 24 घंटे वाली तालिका की आवश्यकता होगी, फिर JOIN
इसके लिए। यदि आप तालिका नहीं बना पा रहे हैं, तो आप इसे अपनी क्वेरी के अंदर बना सकते हैं। यह डेमो देखें
।
SELECT a.hr, IFNULL(b.hourCount, 0) hourCount
FROM
(SELECT 1 AS hr
UNION ALL
SELECT 2
UNION ALL
SELECT 3
UNION ALL
SELECT 4
UNION ALL
SELECT 5
UNION ALL
SELECT 6
UNION ALL
SELECT 7
UNION ALL
SELECT 8
UNION ALL
SELECT 9
UNION ALL
SELECT 10
UNION ALL
SELECT 11
UNION ALL
SELECT 12
UNION ALL
SELECT 13
UNION ALL
SELECT 14
UNION ALL
SELECT 15
UNION ALL
SELECT 16
UNION ALL
SELECT 17
UNION ALL
SELECT 18
UNION ALL
SELECT 19
UNION ALL
SELECT 20
UNION ALL
SELECT 21
UNION ALL
SELECT 22
UNION ALL
SELECT 23
UNION ALL
SELECT 0) a
LEFT JOIN
(SELECT COUNT(id) AS hourCount, HOUR(date) AS hr
FROM `testing`
GROUP BY HOUR(date)) b ON b.hr = a.hr