MySQL Multiple Counts within Date Groups -


select calldate, from_unixtime(floor(unix_timestamp(calldate)/(60*60))*(60*60)) grouptime  , count(*) cntout asterisk.cdr   accountcode = '10102-131' , date (calldate) = date (now()) , calltype = 'outgoing'   group grouptime; 

i have query groups count every hour of date outgoing calls. there way count of incoming in same query?

try this:

select   calldate  from_unixtime(floor(unix_timestamp(calldate)/(60*60))*(60*60)) grouptime,   sum(calltype='incoming') cntin,   sum(calltype='outgoing') cntout  asterisk.cdr  accountcode = '10102-131'    , date (calldate) = date (now())    , calltype in ('incoming', 'outgoing' ) group grouptime; 

sample sql fiddle


Comments

Popular posts from this blog

android - questions about switching from C2DM to GCM -

c++ - Qt setGeometry: Unable to set geometry -

batch file - How to extract all multi-volume RAR archives from subfolders of a folder? -