早教吧作业答案频道 -->其他-->
ORACLE中的CASE……WHEN这两种写法查询结果不一样,请问区别在哪里?A:selectsum(casewhena.cityidin(47,45,35,37,36)then1else0end)甘肃北部,sum(casewhena.cityidin(34,33,32)then1else0end)甘肃东部,sum(casewhe
题目详情
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';
▼优质解答
答案和解析
举个例子:比如
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()函数.当然结果不一样了.
看了 ORACLE中的CASE……...的网友还看了以下:
[sin(45°+a)sin(45°-a)]/[cos(45°+a)cos(45°-a)]= 2020-05-12 …
化简cos^2(45-a)+cos^2(45+a)的结果是 2020-05-12 …
针对word2007的查找和替换,下列说法不正确的是A.查找替换可以设定查找的范围,查找的对象格式 2020-05-17 …
如图,从热气球C处测得地面A、B两点的俯角分别为30°、45°,如果此时热气球C处的高度CD为50 2020-05-17 …
●隐蔽工程施工完毕,应由承建单位的(45),符合要求后,由承建单位通知监理工程师检查验收。(45)A 2020-05-26 …
再查询结果应通过_______告知查询人。A.查询结果通知书B.再查询结果通知书C.电话 2020-05-27 …
查询受理单位详细记录每笔查询业务经办人和复核人、查询号码、_____、查询结果等。A.查询业务方式B 2020-05-27 …
《人民币冠字号查询结果通知书》一式两联,第一联______,第二联_____.A.查询受理单位存档备 2020-05-27 …
有一直尺固定在S1系中,它与Ox轴的夹角是45度,如果S2系以速度u沿Ox方向相对于S1系运动,S 2020-07-16 …
张老师买一本有上下册的儿童读物,他带的钱如果只买上册,刚好买45本,如果买下册,刚好买30本.如果成 2020-11-05 …