oracle统计SQL求助,case when
发布网友
发布时间:2022-04-10 19:08
我来回答
共2个回答
热心网友
时间:2022-04-10 20:38
提供表结构,查询要求。看看我能不能帮你。
你给我的语句按如下调整,写成这样:
SELECT b.Group_Id,
sum(CASE WHEN TRIM(a.Op_Code) = '1000' OR TRIM(a.Op_Code) = '1002' THEN 1 ELSE 0 END) "1|开户",
sum(CASE WHEN TRIM(a.Op_Code) = '1110' THEN 1 ELSE 0 END) "2|补卡",
sum(CASE WHEN TRIM(a.Op_Code) = '1104' OR TRIM(a.Op_Code) = '1111' THEN 1 ELSE 0 END) "3|产品变更",
sum(CASE WHEN TRIM(a.Op_Code) = '1114' THEN 1 ELSE 0 END) "4|改密",
sum(CASE WHEN TRIM(a.Op_Code) = '3920' THEN 1 ELSE 0 END) "4|改资料",
sum(CASE WHEN TRIM(a.Op_Code) NOT IN ('1000','1002','1110','1104','1111','1114','3920') THEN 1 ELSE 0 END) "0|其他业务"
FROM Or_Ordline_Info_201212 a,
Bs_Channelclass_Dict b,
Bs_Loginmsg_Dict c
WHERE b.Group_Id = c.Group_Id
AND a.Login_No = c.Login_No
GROUP BY b.Group_Id
ORDER BY b.Group_Id;
热心网友
时间:2022-04-10 21:56
用decode吧,比case when用起来更简单,
DECODE(条件,值1,翻译值1,值2,翻译值2,...值n,翻译值n,缺省值)来自:求助得到的回答