sql 嵌套 case 语句
有谁知道这个嵌套的 select 语句有什么问题吗?它抱怨缺少 ) ,但我不明白为什么它不起作用(我省略了声明的其他部分)
Select
(CASE WHEN REQUESTS.grade_id = 1 THEN
(CASE WHEN ((date_completed-date_submitted)*24*60)<=30 THEN 'Yes'
ELSE 'No'
END)
ELSE CASE WHEN REQUESTS.grade_id = 2 THEN
(CASE ((date_completed-date_submitted)*24*60) <=120 THEN 'Yes'
ELSE 'No'
END)
ELSE CASE WHEN REQUESTS.grade_id = 3 THEN
(CASE ((date_completed-date_submitted)*24*60)<=14400 THEN 'Yes'
ELSE 'No'
END)
END)in_SLA
如果我这样做
Select
(CASE WHEN REQUESTS.grade_id = 1 THEN
(CASE WHEN ((date_completed-date_submitted)*24*60)<=30 THEN 'Yes'
ELSE 'No'
END)
END) in_sla
它就可以正常工作!
非常感谢任何帮助,
抱歉
,我迟到了,我错过了嵌套案例中的时间
does anyone know whats wrong with this nested select statement? It complains about missing )'s but i can't understand why it doesn't work (i have left off the other bits of the statement)
Select
(CASE WHEN REQUESTS.grade_id = 1 THEN
(CASE WHEN ((date_completed-date_submitted)*24*60)<=30 THEN 'Yes'
ELSE 'No'
END)
ELSE CASE WHEN REQUESTS.grade_id = 2 THEN
(CASE ((date_completed-date_submitted)*24*60) <=120 THEN 'Yes'
ELSE 'No'
END)
ELSE CASE WHEN REQUESTS.grade_id = 3 THEN
(CASE ((date_completed-date_submitted)*24*60)<=14400 THEN 'Yes'
ELSE 'No'
END)
END)in_SLA
If i just do
Select
(CASE WHEN REQUESTS.grade_id = 1 THEN
(CASE WHEN ((date_completed-date_submitted)*24*60)<=30 THEN 'Yes'
ELSE 'No'
END)
END) in_sla
It works fine!
any help is much appreciated
M
sorry being a tard i'm missing the whens from the nested cases
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它应该是:
即每种情况只是“WHEN”而不是“ELSE CASE WHEN”。
我很想简化为:
It should be:
i.e. just "WHEN" not "ELSE CASE WHEN" for each case.
I'd be tempted to simplify to: