gpt4 book ai didi

sql - INNER Join 的案例声明

转载 作者:行者123 更新时间:2023-12-02 07:45:46 25 4
gpt4 key购买 nike

尝试在内部联接上使用 CASE 语句,但我得到的只是语法错误,有人对此有任何建议吗?

这是代码

 SELECT  
Call_type_ID,
SUM (staging.dbo.outgoing_measure.ring_time) AS Ring_Time,
SUM (staging.dbo.outgoing_measure.hold_time) As Hold_Time,
SUM (staging.dbo.outgoing_measure.talk_time) AS Talk_Time,
SUM (staging.dbo.outgoing_measure.acw_time) AS ACW_Time,
COUNT(*) CallCount
FROM outgoing_measure

INNER JOIN datamartend.dbo.Call_Type_Dim ON
CASE
WHEN
CTICallType_ID = 1
AND CTIAgentCallType_ID = 0
AND Abandoned IS NULL
AND AnsTime > 0
AND CallState IS NULL
THEN Call_Type_ID = 10
WHEN
CTICallType_ID = 1
AND CTIAgentCallType_ID = 0
AND Abandoned IS NULL
AND AnsTime > 0
AND CallState = 1
THEN call_Type_id = 11
WHEN
CTICallType_ID = 1
AND CTIAgentCallType_ID = 0
AND Abandoned = 1
AND AnsTime IS NULL
AND CallState IS NULL
THEN call_type_ID = 12
ELSE call_type_id = 1
END

Group by call_Type_id

这是我第一次使用 case 语句,更不用说将它们与内部联接相结合,所以如果我完全搞砸了,我很抱歉。

我遇到的语法错误是:

此处 = 和 WHEN 的语法不正确

THEN Call_Type_ID = 10
WHEN

语法错误,需要在 GROUP BY 上进行 CONVERSION

最佳答案

您似乎正在尝试在案例中创建Where子句,但您应该将案例的结果与Call_Type_ID(或您想要的任何其他字段)进行比较,如我在下面编写的示例中所示希望对您有帮助!

有时我会在外壳上使用括号,以便更容易看到它们的开始和停止位置。

INNER JOIN datamartend.dbo.Call_Type_Dim ON 
(CASE
WHEN CTICallType_ID = 1
AND CTIAgentCallType_ID = 0
AND Abandoned IS NULL
AND AnsTime > 0
AND CallState IS NULL
THEN 10
WHEN CTICallType_ID = 1
AND CTIAgentCallType_ID = 0
AND Abandoned IS NULL
AND AnsTime > 0
AND CallState = 1
THEN 11
WHEN
CTICallType_ID = 1
AND CTIAgentCallType_ID = 0
AND Abandoned = 1
AND AnsTime IS NULL
AND CallState IS NULL
THEN 12
ELSE 1
END) = Call_Type_ID -- Insert something here to join on.

关于sql - INNER Join 的案例声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15786611/

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