gpt4 book ai didi

具有多个 'case' 值的 mysql 'WHEN'

转载 作者:可可西里 更新时间:2023-11-01 07:30:55 25 4
gpt4 key购买 nike

我有一个查询需要对其他 2 列为 true 的列进行计数。当“DealerName”如“%MINI%”和“DealerContact_Y”= 1 时,我需要计算“DealerName”

但我不确定语法。此查询产生错误

SELECT DealerName,
count(DealerShipId) as dealersContacted,
CASE WHEN
DealerName LIKE "%MINI%", WHEN DealerContact_Y = 1
THEN Count(DealerContact_Y) END as Mini_contacted_yes,
Campaign,
DealerId
FROM tblsummaryResults

有没有办法在 case 语句中执行多个 WHENS?

最佳答案

您可以这样写,使用 DealerName LIKE '%MINI%' AND DealerContact_Y = 1:

SELECT DealerName,
count(DealerShipId) as dealersContacted,
count(CASE
WHEN DealerName LIKE '%MINI%'
AND DealerContact_Y = 1
THEN DealerContact_Y END) as Mini_contacted_yes,
Campaign,
DealerId
FROM tblsummaryResults

关于具有多个 'case' 值的 mysql 'WHEN',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14752775/

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