I am joining second table (job_timetable) with call_log table . I am having multiple rows of data for each user_id ( common field in both the tables )in job_timetable table . So I am using group by . I want to add the values of column( counter) for each set of user_id .
Table call_log
user_id duration
5019 12
2345 23
5019 14
Table job_timetable
user_id counter
5019 1
5019 3
2345 2
Expected output :
user_id duration average duration countersum
5019 26 13 4
2345 23 23 2
Current output : Returns nothing
What is wrong with my query ?
SELECT call_log.user_id,SUM(call_log.duration) as duration,avg(call_log.duration) as
average_duration,countersum
FROM call_log
LEFT JOIN (SELECT user_id,sum(counter) as countersum FROM job_timetable
GROUP BY user_id ) b on call_log.user_id= b.user_id
where call_log.user_id is not null
group by call_log.user_id order by call_log.user_id asc;