当前位置: > ORACLE中的CASE……WHEN...
题目
ORACLE中的CASE……WHEN
这两种写法查询结果不一样,请问区别在哪里?
A:
select sum(case when a.city_id in (47,45,35,37,36) then
1 else 0 end) 甘肃北部,
sum(case when a.city_id in (34,33,32) then
1 else 0 end) 甘肃东部,
sum(case when a.city_id in (39,38,41) then
1 else 0 end)甘肃南部,
sum(case when a.city_id in (30,31,43) then
1 else 0 end)甘肃中部
from agt_channel a
where a.st_id = '10A';
B:
select sum(case when a.city_id in (47,45,35,37,36) then
1 else 0 end) 甘肃北部,
sum(case when a.city_id in (34,33,32) then
2 else 0 end) 甘肃东部,
sum(case when a.city_id in (39,38,41) then
3 else 0 end)甘肃南部,
sum(case when a.city_id in (30,31,43) then
4 else 0 end)甘肃中部
from agt_channel a
where a.st_id = '10A';

提问时间:2020-11-08

答案
举个例子:比如
a中 当a.city_id in (34, 33, 32) 返回的是1
b中 当a.city_id in (34, 33, 32) 时,是返回的2 你这又是个sum()函数.当然结果不一样了.
举一反三
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
1,人们染上烟瘾,最终因吸烟使自己丧命.
版权所有 CopyRight © 2012-2019 超级试练试题库 All Rights Reserved.