I have the following query:
SELECT count(*) as \'totalCalls\', HOUR(`end`) as \'Hour\'
FROM callsDataTable
WHERE company IN (
SELECT number
FROM pr
You need a Hour
table and then do a left Outer Join
with the Hour_table
.
Which will ensure that all hours
will be returned. If hour
doesn't exists in callsDataTable
then count will be 0
.
Hours Table
create table hours_table (hours int);
insert into hours_table values(0);
insert into hours_table values(1);
...
insert into hours_table values(23);
Query:
SELECT count(HOUR(`end`)) as 'totalCalls', HT.Hours as 'Hour'
FROM Hours_table HT left Outer join callsDataTable CD
on HT.Hours = HOUR(`end`)
WHERE company IN (
SELECT number
FROM products
WHERE products.id IN (@_PRODUCTS))
AND YEAR(`end`) = @_YEAR AND MONTH(`end`) = @_MONTH
group by HT.Hours