日期:2014-05-18  浏览次数:20585 次

麻烦各位老师看看这条SQL语句的问题?
select a.*,b.mingcheng,c.mingma,d.mingcheng as mch,e.mingcheng as pl,f.DFMingCheng as zj,g.Expr1 from Tbl_checkIn a,tbl_diqu b,tbl_ShouPiao c,tbl_YanPiaoDian d,tbl_PiaoLei e,Tbl_SFZ f,zaozhuangUser.tbl_S g where .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>='6519' and mingma<='6619' and convert(char(10),CheckInTime,120) >= '20120610' and convert(char(10),CheckInTime,120) <= '20120625' and a.ZhengJian=g.ZhengJian order by a.zhengjian


之前没加g.Expr1、 zgUser.tbl_S g, a.ZhengJian=g.ZhengJian是能查出数据的,但是加完后就不显示结果了,也没有报错查询结果为空,g.Expr1表项是证件的使用次数,a.ZhengJian=g.ZhengJian这个筛选条件写法有错误吗?是不是已经有 left(a.zhengjian,6)=f.SFZBianHao 这个条件就不能再加了?我把a,g表的zhengjian单独拿出来链接是有结果的,麻烦各位老师给指点下,谢谢!

------解决方案--------------------
最好规范写法,前面的表改成显式的内连接,最后的g表改为左连接
另外,你的写法没有优化