ORACLE中的CASE……WHEN这两种写法查询结果不一样,请问区别在哪里?A:select sum(case when a.cityid in (47,45,35,37,36) then1 else 0 end) 甘肃北部,sum(case when a.cityid in (34,33,32) then1 else 0 end) 甘肃东部,sum(case when a.cityid in (39,38,41) then1 else 0 end)甘肃南部,sum(case when a.cityid in (30,31,43) then1 else 0 end)甘肃中部from agtchannel awhere a.stid = '10A';B:select sum(case when a.cityid in (47,45,35,37,36) then1 else 0 end) 甘肃北部,sum(case when a.cityid in (34,33,32) then2 else 0 end) 甘肃东部,sum(case when a.cityid in (39,38,41) then3 else 0 end)甘肃南部,sum(case when a.cityid in (30,31,43) then4 else 0 end)甘肃中部from agtchannel awhere a.stid = '10A';
网友回答
【答案】 举个例子:比如
a中 当a.city_id in (34, 33, 32) 返回的是1
b中 当a.city_id in (34, 33, 32) 时,是返回的2 你这又是个sum()函数.当然结果不一样了.