select isnull(a.mc,b.mc) as mc,isnull(a.sl,0)-isnull(b.sl,0),isnull(a.dj,b.dj) from
(select mc,dj,sum(sl) as sl from in_table group by mc,dj where rq between @date1 and @date2 ) a
full join
(select mc,dj,sum(sl) as sl from out_table group by mc,dj where rq between @date1 and @date2 ) b
on a.mc=b.mc and a.dj=b.dj
(select mc,dj,sum(sl) as sl from in_table group by mc,dj where rq between @date1 and @date2 ) a
full join
(select mc,dj,sum(sl) as sl from out_table group by mc,dj where rq between @date1 and @date2 ) b
on a.mc=b.mc and a.dj=b.dj
select isnull(a.mc,b.mc) as mc,isnull(a.sl,0)-isnull(b.sl,0),isnull(a.dj,b.dj) from
(select mc,dj,sum(sl) as sl from in_table where rq between @date1 and @date2 group by mc,dj ) a
full join
(select mc,dj,sum(sl) as sl from out_table where rq between @date1 and @date2 group by mc,dj ) b
on a.mc=b.mc and a.dj=b.dj
数量 = (select sum(a.数量) - isnull(sum(数量), 0) from 出库表 where a.名称 = 名称 and a.等级 = 等级 and 日期 between @data1 and @data2),
等级 from 入库表 a where 日期 between @data1 and @data2 group by 名称, 等级
(select mc,dj,sum(sl) in_num from in_table group by mc,dj) a
left join (select mc,dj,sum(sl) out_num from out_table group by mc,dj) b
on a.mc=b.mc and a.dj= b.dj
如果要考慮日期的話,就把日期區間作為條件加入子查詢中。
into ckcpkc from
(select bcdh_q,bcdh_j,bcdh_h,kh,bl,zz,sz,fd,pch,ys,jclx,sum(js) as js,sum(sl) as sl from ckcpjc group by bcdh_j,bcdh_q,bcdh_h,jclx) cpjc
left join
(select bcdh_q,bcdh_j,bcdh_h,kh,bl,zz,sz,fd,pch,ys,jclx,sum(js) as js,sum(sl) as sl from ckcpcc group by bcdh_j,bcdh_q,bcdh_h,jclx) cpcc
on cpjc.bcdh_j=cpcc.bcdh_j and cpjc.bcdh_q=cpcc.bcdh_q and cpjc.bcdh_h=cpcc.bcdh_h and cpjc.jclx=cpcc.jclx能帮忙看下这段语句错在什么地方!