各位大大你们好,注册很久了 但是第一次发贴.
想请教一个问题.
如果有两个表 t1 和 t2 , t1中有列A,t2中有列B.需求是 如果当t1中的A等于t2中的B时那么 显示'已参照'我想到的办法是用case whencase when A=B then '已参照' esle '' end那么在实际使用的时候会出现一个问题,会出现2行数据,一行是已参照,一行是空.
因为A列中的一个值可能等于B中的一列,但是B列中还有其他的值就不等于,所以只要是有等于数据固定会输出一个为空的行.想知道,怎样才能当 B列中有一个等于A列的时候就 只输出一行 已参照,不输出空的.先谢谢大家了.
想请教一个问题.
如果有两个表 t1 和 t2 , t1中有列A,t2中有列B.需求是 如果当t1中的A等于t2中的B时那么 显示'已参照'我想到的办法是用case whencase when A=B then '已参照' esle '' end那么在实际使用的时候会出现一个问题,会出现2行数据,一行是已参照,一行是空.
因为A列中的一个值可能等于B中的一列,但是B列中还有其他的值就不等于,所以只要是有等于数据固定会输出一个为空的行.想知道,怎样才能当 B列中有一个等于A列的时候就 只输出一行 已参照,不输出空的.先谢谢大家了.
解决方案 »
- Having 离不开 group by ?
- 对话框的MFC程序通过ADO链接Oracle数据库
- 急求一条sql语句,在线等!
- oracle如何横向显示字符
- 请教个sql语句的写法,请各位帮忙了
- Oracle中的trigger
- 一个sql语句
- oracle 还是sql server
- 序号自增的问题
- 请问有人用过Cobub Razor吗?遇到问题求解决!
- 求救..ORA-12154: TNS:could not resolve the connect identifier specified~~搞了好久了没解决!
- 在執行alter table move tablespace之後,table的存檔數度變得超慢的?
case when f.zkey=f2.vlastbillcode then '已参照'end 是否参照
from (select zxmmc,zphrq,c.vcname,zkey from
(select z.xmmc zxmmc,z.phrq zphrq,z.paihaokey zkey,a.pk_customer zpk_customer
from(select fdc_bd_project.vname xmmc,
sm_user.user_name zygw,ps_so_queue.dapprovedate phrq,ps_so_queue.nyqueuemny ysphf,
ps_so_queue.pk_queue,
ps_so_queue.vqueuebargainnum paihaokey
from ps_so_queue_confine
left join fdc_bd_project on ps_so_queue_confine.pk_project_build=fdc_bd_project.pk_project
left join ps_so_queue on ps_so_queue_confine.pk_queue=ps_so_queue.pk_queue
left join sm_user on ps_so_queue.voperatorid=sm_user.cuserid
where ps_so_queue_confine.dr=0 and ps_so_queue.dr=0 ) z
left join PS_SO_QUEUE_CUSTOMER a on z.pk_queue=a.pk_queue) a1
left join ps_cmg_customer c on a1.zpk_customer=c.pk_customer)f, --排号
(select vlastbillcode from
(select ps_so_engage.vlastbillcode
from ps_so_engage where vlastbill='9466' and vlastbillcode is not null
and ps_so_engage.dr='0') --预定
union
(select ps_so_subsc.vlastbillcode
from ps_so_subsc where vlastbill='9466' and vlastbillcode is not null
and ps_so_subsc.dr='0') --认购
union
(select ps_so_sign.vlastbillcode
from ps_so_sign where vlastbill='9466' and vlastbillcode is not null and ps_so_sign.dr='0'))f2 --签约
group by f.zxmmc,f.zphrq,f.vcname,f.zkey,case when f.zkey=f2.vlastbillcode then '已参照'end
order by f.vcname
select case
when t2.b is not null then
'已参照'
else
'na'
end ca
from t1
left outer join t2
on t1.a = t2.b
select case
when t2.b is not null then
'已参照'
else
'na'
end ca
from t1
left outer join t2
on t1.a = t2.b
where t2.b is not null