gpt4 book ai didi

sql嵌套case语句

转载 作者:行者123 更新时间:2023-12-04 02:59:59 24 4
gpt4 key购买 nike

有谁知道这个嵌套的 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

它工作正常!

非常感谢任何帮助



抱歉,我迟到了,我错过了嵌套案例的时间

最佳答案

应该是:

Select
(CASE WHEN REQUESTS.grade_id = 1 THEN
(CASE WHEN ((date_completed-date_submitted)*24*60)<=30 THEN 'Yes'
ELSE 'No'
END)
WHEN REQUESTS.grade_id = 2 THEN
(CASE ((date_completed-date_submitted)*24*60) <=120 THEN 'Yes'
ELSE 'No'
END)
WHEN REQUESTS.grade_id = 3 THEN
(CASE ((date_completed-date_submitted)*24*60)<=14400 THEN 'Yes'
ELSE 'No'
END)
END)in_SLA

即对于每种情况,只是“WHEN”而不是“ELSE CASE WHEN”。

我很想简化为:
Select
CASE WHEN (REQUESTS.grade_id = 1 AND (date_completed-date_submitted)*24*60 <= 30)
OR (REQUESTS.grade_id = 2 AND (date_completed-date_submitted)*24*60 <=120)
OR (REQUESTS.grade_id = 3 AND (date_completed-date_submitted)*24*60 <=14400)
THEN 'Yes'
ELSE 'No'
END in_SLA

关于sql嵌套case语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3187789/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com