当前位置: 代码迷 >> Oracle开发 >> *有没有将“存不存在”的状态select出来的SQL语句?该怎么处理
  详细解决方案

*有没有将“存不存在”的状态select出来的SQL语句?该怎么处理

热度:104   发布时间:2016-04-24 07:58:49.0
****有没有将“存不存在”的状态select出来的SQL语句??
假设有两个表A和B,结构如下:

A:
s_no     s_name
1           aa
2           bb
3           cc
4           dd


B:
sss_name     sss_pts
  aa               123
  cc               99


我想知道A表中的记录在B中有没有对应的记录,如果有的话给出sss_pts,没有的话也有要一个量说“没有!”。
我期望得到的结果集是:

s_name     s_status     sss_pts
aa               yes           123
bb               no
cc               yes           99
dd               no

……有没有将“存不存在”的状态select出来的SQL语句?

------解决方案--------------------
select t1.s_name,
case t2.sss_pts
when null then
'No '
else
'Yes '
end as s_status,
t2.sss_pts
from A t1, B t2
where t1.s_name = t2.sss_name(+);
多了个when ,case 后when不要
------解决方案--------------------
Oracle不支持Case...When吧,用nvl吧.....

select t1.s_name,
nvl(t2.sss_pts, 'No ') sss_pts
from A t1, B t2
where t1.s_name = t2.sss_name(+);
------解决方案--------------------
谁说oracle不支持case...when...的?绝对支持
------解决方案--------------------
Oracle支持case啊,我在这边测试都可以的
  相关解决方案