vendredi 10 juin 2016

sql check for no result in group by clause

I have a sql

select sum(quantity), Hour(posted)
from orders
where posted between '' and ''
group by Hour(posted)

result may be

sum, hour
10, 0
12, 1
13, 3 // note 2 missing in hours
13, 5 // note hour 4 is missing

what I need is

sum,hour
10,0
12,1
0, 2 // 0 for missing hour ( where no record was found in that hour)
13,3 
0, 4 // 0 for missing hour ( where no record was found in that hour)
13,5 

how can I do it?? any help is appreciated

Aucun commentaire:

Enregistrer un commentaire