日期:2014-05-17 浏览次数:20469 次
select ww.*,qq.renshu from (select a.*,b.mingcheng,c.mingma,d.mingcheng as mch,e.mingcheng as pl,f.DFMingCheng as zj from Tbl_checkIn a,tbl_diqu b,tbl_ShouPiao c,tbl_YanPiaoDian d,tbl_PiaoLei e,Tbl_SFZ f where a.diqu=b.bianhao and a.KaHao=c.kahao and a.CheckInNo=d.bianhao and left(a.zhengjian,6)=f.SFZBianHao and a.piaolei=e.bianhao and mingma>='11' and mingma<='22' and convert(char(10),CheckInTime,120) >= '20120615' and convert(char(10),CheckInTime,120) <= '20120625') ww join (select zhengjian,sum(renshu) as renshu from tbl_checkin group by zhengjian) qq on ww.zhengjian =qq.zhengjian
--这种写法测试通过 select * from sys_code where 1=1 and ( ( id>'106' and id<'108') or ( id>'112' and id<'14') ) and 1=1
------解决方案--------------------
--..... SELECT * FROM tb WHERE ( CASE WHEN mingma>='11' and f_ConsumerName<='22' THEN 1 ELSE 0 END + CASE WHEN mingma>='28' and mingma<='32' THEN 1 ELSE 0 END + CASE WHEN mingma>='57' and mingma<='75' THEN 1 ELSE 0 END + CASE WHEN mingma>='82' and mingma<='91' THEN 1 ELSE 0 END + ) >= 1 --组合条件搜索,当上述4种条件任意一种或多种同时满足