日期:2014-05-16  浏览次数:21109 次

判断A列中是否有数据等于B列中的值
各位大大你们好,注册很久了 但是第一次发贴.
想请教一个问题.
如果有两个表 t1 和 t2 , t1中有列A,t2中有列B.

需求是 如果当t1中的A等于t2中的B时那么 显示'已参照'

我想到的办法是用case when

case when A=B then '已参照' esle '' end

那么在实际使用的时候会出现一个问题,会出现2行数据,一行是已参照,一行是空.
因为A列中的一个值可能等于B中的一列,但是B列中还有其他的值就不等于,所以只要是有等于数据固定会输出一个为空的行.

想知道,怎样才能当 B列中有一个等于A列的时候就 只输出一行 已参照,不输出空的.

先谢谢大家了.
------解决方案--------------------
没有一个人呀 - - 伤心...

付下代码把- -

select f.zxmmc 排号项目,f.zphrq 排号日期,f.vcname 客户姓名,f.zkey 排号合同号,
       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