MySQL - No se puede crear la vista con la variable SET dentro
Estoy tratando de crear una vista conSET @rank = 0;
Por dentro me está dando errores. He estado intentando cosas diferentes pero no funciona. ¿Alguien por favor me puede indicar la dirección correcta?
CREATE VIEW S1_Bottom_Performer_AHT as (
SET @rank=0
SELECT @rank := @rank+1 AS '#',
ei.SM,
ei.TM,
es.Month_Date,
ei.emp_id,
ei.DNAME,
ei.STATUS,
ei.SHIFT,
ei.SKILL,
ei.HIRE_DATE,
ifnull(TIMESTAMPDIFF(MONTH, ei.HIRE_DATE, now()), '-') AS Tenure,
ifnull(es.Call_Handled, '-') AS Call_Handled,
ifnull(es.AHT, '-') AS AHT
FROM mtl_extended_info ei
LEFT OUTER JOIN
( SELECT es.Employee_ID,
es.Month_Date,
sum(es.Calls_Handled_Ct) AS Call_Handled,
round((sum(es.I_Talk_Time_Sec) + sum(es.Hold_Time_Sec) + sum(es.I_Work_Time_Sec) + sum(es.I_AUX_Out_Time_Sec)) / sum(es.Calls_Handled_Ct)) AS AHT
FROM cdl_agent_call_voume_gen es
WHERE es.Month_Date = '2013-09-01'
GROUP BY es.Employee_ID,
es.Month_Date ) es ON es.Employee_ID = ei.emp_id
WHERE es.Month_Date = '2013-09-01'
AND ei.Visible = 1
AND ei.SKILL != 'RSD'
GROUP BY ei.emp_id
ORDER BY es.AHT DESC LIMIT 80);
Mensaje de error:
#1064 - 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 'SET @rank=0
SELECT @rank := @rank+1 AS '#',
ei.SM,
' at line 2