题目
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';
这两种写法查询结果不一样,请问区别在哪里?
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()函数.当然结果不一样了.
a中 当a.city_id in (34, 33, 32) 返回的是1
b中 当a.city_id in (34, 33, 32) 时,是返回的2 你这又是个sum()函数.当然结果不一样了.
举一反三
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
1,人们染上烟瘾,最终因吸烟使自己丧命.
最新试题
热门考点
- 1季羡林笑着说:“我小时候父母不在跟前,叔父不大管我,可是他不让我看闲书.”{改转述句}
- 21又6分之1加5又2分之1加1又4分之1等于必采
- 3一台压路机,滚筒直径1米,宽是一点二米,工作时每分钟转动16周,这台压路机滚动3分钟前进了多少米?
- 4《红字》(或者是《圣诞欢歌》再或者是特别简短的英文读物)简介(纯英文版)有的给我.谢谢了.字数不用
- 5It was my daughter Linda and his daughter Jane who did it.
- 6求助:历史上唐朝和明朝那个更强盛?
- 7某电脑公司2001年的各项经营中,一月份的营业额为200万元,一月、二月、三月的营业额共950万元,如果平均每月营业额的增长率相同,求这个增长率.
- 8求曲线y=4/x与y=(x-3)^2所围成的图形面积
- 9Today there are only a few forests left.People must ________
- 102010年12月15日平安中国观后感