mysql - Sum of a joined table -
it possible has been answered somewhere couldn't find it. appreciate if me sql statement again.
this sql statement have far:
select * , round( (rate * time_to_sec( total ) /3600 ) , 2) revenue (select event.eventid, event.staffid, event.role, timediff( time, pause ) total, case when position = 'teamleader' (teamleader) when position = 'waiter' (waiter) else '0' end rate event, rates, eventoverview storno =0 , event.eventid= eventoverview.eventid , event.clientid = rates.clientid group event.eventid, event.clientid)q1 group q1.staffid
the table getting giving me total rate per staff , event. achieve sum of rates per staff. sum of revenue.
hope can me. in advance
you can enclose query in subquery , in outer query this:
select *, sum(revenue) ( select * , round( (rate * time_to_sec( total ) /3600 ) , 2) revenue ( select event.eventid, event.staffid, event.role, timediff( time, pause ) total, case when position = 'teamleader' (teamleader) when position = 'waiter' (waiter) else '0' end rate event inner join rates on event.clientid = rates.clientid inner join eventoverview on event.eventid = eventoverview.eventid storno =0 group event.eventid, event.clientid )q1 group q1.staffid ) t group staffid;
note that: might inconsistent data, due use of select *
group by
staffid
only, columns not in group by
clause need enclosed aggregate function otherwise mysql arbitrary value it. not recommended , it not standard way so.
Comments
Post a Comment