mysql set variable_MySQL-无法在内部使用SET变量创建视图

bd96500e110b49cbb3cd949968f18be7.png

I am trying to create a view with SET @rank = 0; inside but it's giving me errors. Been trying different things but it's not working. Can anyone please point me to the right direction?

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);

Error message:

#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

解决方案

I think you cannot do that.

As from the MYSQL guidelines:

A view definition is subject to the following restrictions:

[ deletia ]

The SELECT statement cannot refer to system or user variables.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值