select a.rq,b.spbh,b.spmch,b.spchd,sum(c.shpshl),sum(c.psshl),sum(c.psje)
from pdhz a join pdmx b on a.djbh = b.djbh join spkfk c on
b.spdid = c.spid
where a.rq between '2003-11-01' and '2003-11-15'
group by a.rq,b.spbh,b.spmch,b.spchd
having sum(psje)>300  or sum (psje)<-300

解决方案 »

  1.   

    服务器: 消息 180,级别 15,状态 1,行 1
    Line 1: Incorrect syntax near ','.还是不行,我的如下:hwsp  货位商品库   字段  hw,spid ,jwh
    select a.jwh,b.* from hwsp a,
    (select a.spid,a.spbh,a.spmch,a.shpgg,a.dw,sum(c.psshl) as shl,sum(c.psje) as je,a.shpchd from spkfk a,pdhz b,pdmx c
    where a.spid=c.spid and b.djbh=c.djbh and b.rq>'2003-11-22' and b.hw='HWI00000002'
    group by a.spid,a.spbh,a.spmch,a.shpgg,a.dw,a.shpchd) b
    where a.spid=b.spid and a.hw='HWI00000002' and (b.shl>9 or b.shl<-9 or b.je>300 or b.je<-300)
    order by a.jwh  /*  or    order by b.spbh   */但也不行,错在那里???急!!
      

  2.   

    Select rq,spbh,spmch,spchd,sum(shpshl),sum(psshl),sum(psje) 
    from spkfk a,pdhz b,pdmx c
    where a.spid=c.spid and b.djbh=c.djbh
    and b.rq between '2003-11-01' and '2003-11-15'
    group by rq,spbh,spmch,spchd
    having sum(psje)>300 or sum (psje)<-300