如何在我的“案例表达”中使用int
?
这是我的查询,如果找到IN
之类的任何匹配作为mumbai
,我想要计数:
mumbai
答案 0 :(得分:1)
你很接近,你只需要用IN
逗号分隔值而不是OR
,CASE
表达式有两种格式,在{WHEN
后面加上标准的字段{1}}更灵活,所以我更喜欢单独使用它:
SELECT TYPEOFPRODUCT
,SUM( CASE WHEN BRANCH IN('Mumbai1','Mumbai2') THEN 1 ELSE 0 END) AS Mumbai
,SUM( CASE WHEN BRANCH IN('Delhi1', 'DelhiMain') THEN 1 ELSE 0 END) AS Delhi
FROM los_ext
GROUP BY TYPEOFPRODUCT
答案 1 :(得分:0)
其查询选择各个分支的总和
select TYPEOFPRODUCT,
SUM(CASE WHEN (BRANCH = 'Mumbai1' OR BRANCH = 'Mumbai2' ) THEN 1 ELSE 0 END) AS 'Mumbai',
SUM(CASE WHEN (BRANCH = 'Delhi1' OR BRANCH = 'DelhiMain' ) THEN 1 ELSE 0 END) AS 'Delhi'
from los_ext
group by TYPEOFPRODUCT