This query is done through a web page that queries a database, when playing this query directly in MySQL it returns the error
"ERROR 1248 (42000): Every derived table must have its own alias"
Could someone help?
select * from ( select a.id as ID,
a.tn as CODIGO,
a.title as TITULO,
(d.solution_time / 60) as HorasSLA,
(d.first_response_time / 60) as HorasResposta,
b.id as cdFila, b.name as FILA,
c.id as cdServico,
c.name as SERVICO,
d.id as cdSLA,
d.name as SLA,
e.id as cdUser,
concat(e.first_name, ' ', e.last_name) as USER,
f.id as cdStatus,
f.name as STATUS,
a.customer_user_id as CLIENTE,
a.customer_id as EMAIL,
a.create_time as REGISTRO,
DATE_ADD(a.create_time,INTERVAL d.solution_time MINUTE) AS LIMITE,
DATE_ADD(a.create_time,INTERVAL d.first_response_time MINUTE) AS RESPOSTA,
COALESCE(
(SELECT MAX(create_time)
FROM ticket_history
WHERE ticket_id = a.id
AND state_id = f.id
and history_type_id not in (30, 40)),
CURRENT_TIMESTAMP()) AS ULTEVENTO,
coalesce(jt.ST_INFRA, 'N') as ST_INFRA,
(select max(create_time)
from ticket_history
where ticket_id = a.id
and state_id = 2
and history_type_id = 27) as DT_CLOSED
From ticket a
Join queue b on(a.queue_id = b.id)
Join service c on (a.service_id = c.id)
Join sla d on(a.sla_id = d.id)
Join users e on(a.user_id = e.id)
Join ticket_state f on(a.ticket_state_id = f.id)
Left Join JornadaTrabalho jt on (e.id = jt.user_id)
Where 1 = 1 And e.id = 94
And COALESCE((SELECT MAX(create_time)
FROM ticket_history
WHERE ticket_id = a.id
AND state_id = f.id and history_type_id not in (30, 40)),
CURRENT_TIMESTAMP()) between '2021-11-01 00:00:00' and '2021-11-29 23:59:59'
And f.id = 2 )