当前位置:操作系统 > Unix/Linux >>

数据库多条件同时成立判断


数据库多条件同时成立判断
 
select *
into #data5
from #data4 as a
where a.contractCode in(
select ct.contractCode
from #data as a
left join  ip_ct_bill as cb
on a.billid = cb.id  www.zzzyk.com  
left join ip_ct_contract as ct
on cb.contractid =ct.id
group by ct.contractCode
having sum(isnull(cb.billmoney,0))<>0)
--只需要定义一个判断条件 ,多种条件成立 一个值 与一个值对比,否则取另外一个值,与另外一个值对比。
and case when substring(a.ordercode,1,1) = 'z' or isnull(a.money,0)<>0  then 1 else 0 end = 1
 
这样即可达到一个 在同一数据中,把一部分数据排除在外,去筛选另外一部分数据。
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,