mysql - How to count rows by group by and and add this to subquery? -


i need count rows gouped hours , add select subquery, got error on line and date(created_at) = t.day_start , user_id = t.user_id

here query:

select     count(*)     (         select             hour (call_start_at) hours,             count(*) calls                     calls                     1         , user_id = 8         , call_start_at >= '2016-01-06 00:00:00'         , call_start_at <= '2016-01-06 23:59:59'         group             hour (call_start_at)     ) t1 

and try add select subquery, wrong on marked line t.day_start , t.user_id when changing.

here test:

select     t2.name,     t2.calls,     round(calling_time * 100 / working_time, 2) percent,     t2.calling_time,     t2.working_time     (select         t.name,         (select count(*) calls c date(c.created_at) = t.day_start , c.user_id = t.user_id) calls,         (select             count(*)                  (select             hour(call_start_at) hours,             count(*) calls                      calls         1             , date(created_at) = t.day_start , user_id = t.user_id // marked line         group             hour(call_start_at)) t3         ) row_count,         (select sum(call_length) calls c date(c.created_at) = t.day_start , c.user_id = t.user_id) calling_time,         sum(t.working_time) working_time             (select             u.username name,             u.id user_id,             date(uw.start) day_start,             uw.length working_time                     users u             left join users_worktime uw on uw.user_id = u.id         1             , u.type = 'agent'             , uw.start >= '2016-01-06 00:00:00'             , uw.start <= '2016-01-06 23:59:59'         ) t     group         t.name, t.user_id, t.day_start     ) t2 

you can more write query as:

    select count(distinct hour(call_start_at)) num      calls     1 ,           user_id = 8 ,           call_start_at >= '2016-01-06 00:00:00' ,           call_start_at <= '2016-01-06 23:59:59' 

this allow use correlation clause.

note: ignores null values. assume not problem (it fixed if is).


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -