请教多语句合并的问题?
请教各位老师,我有两条语句,想要把查询一和二合并一条语句执行,查询二的zhengjian需要查询一的结果来执行,是否可以实现呢?
查询一
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>='55622'
and mingma<='007008000055634' and convert(char(10),CheckInTime,120) >= '20120615'
and convert(char(10),CheckInTime,120) <= '20120625' order by a.zhengjian
查询二
select sum(renshu) from tbl_checkin where zhengjian='.......'
------解决方案--------------------
你的应该是sql 2000吧,那就不要用row_number了
直接把他去掉
SQL code
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>='55622'
and mingma<='007008000055634' and convert(char(10),CheckInTime,120) >= '20120615'
and convert(char(10),CheckInTime,120) <= '20120625' --order by a.zhengjian
) ww join
(select zhengjian,sum(renshu) as renshu from tbl_checkin group by zhengjian
) qq on ww.zhengjian =qq.zhengjian