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

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -