请各位老大和zjcxc(邹建)进来看看啊!复杂查询问题?
原帖子在
http://community.csdn.net/Expert/topic/3022/3022143.xml?temp=.6390345
select a.wdid
,出货总数=sum(a.isum)
,正价出货数=sum(case a.tjflag when 0 then a.isum else 0 end)
,正价出货额=sum(case a.tjflag when 0 then a.isum*a.jg_zj*(1-b.kd)*(1-b.fd)*(1-b.fl) else 0 end)
,特价出货数=sum(case a.tjflag when 1 then a.isum else 0 end)
,特价出货额=sum(case a.tjflag when 1 then a.isum*a.jg_zj*(1-a.tj_kd)*(1-a.tj_fd)*(1-a.tj_fl) else 0 end)--
,销售成本合计=sum(a.isum*a.jg_cb)
from chd_cpmx a
right join chd_yywd b on a.tjflag=0 and a.wdid=b.wdid and b.xqbh=@xqbh and (b.lrsj between @Strdate and @EndDate)and (b.js_yj=1)
where (a.lrsj between @Strdate and @EndDate) and substring(a.wdid,1,4)=@xqbh
group by a.wdid
为什么在查询一段时间记录时数据×天数,错在哪里,如何改正。