I am wanting to alias 3 variables in my query, total_time_taken and average and request_count.
The average is meant to calculate the total_time_taken / request_count to return average however it is giving me a syntax error
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select(created_at, assigned_at, SUM(TIMESTAMPDIFF(SECOND, requests.created_at, r' at line 4
The query is below.
select
*,
COUNT(*) as request_count,
select(created_at, assigned_at, SUM(TIMESTAMPDIFF(SECOND, requests.created_at, requests.assigned_at)) from requests) as total_time_taken,
total_time_taken / request_count as average
from
`requests`
where
`deleted_at` is null
and
`submitted_at` >= '2017-03-30 00:00:00'
and
`requests`.`deleted_at` is null
group by
`engineer_id`
limit 5
(in front of the 2ndselect