select - sql check for no result in group by clause -


i have sql query mysql

select sum(quantity), hour(posted) orders posted between '05-10-2014' , '05-10-2014' // timestamp here group hour(posted) 

result may

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

what need

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

how can it?? appreciated

if using sqlserver can use following tsql query desired results:

with [hours]  ( select distinct hour = number  master..[spt_values]  number between 1 , 24 )  select isnull(sum(orders.quantity),0) quantity, [hours].[hour] hours left join orders  on hours.hour =   datepart(hour,posted) group [hours].[hour] 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -