日期:2014-05-18 浏览次数:20620 次
SELECT buhuo = CASE WHEN b.slqty > a.qty THEN '*' ELSE '' END, c.PLUno, c.pluname, mll = (c.slprc - c.csprc) / c.slprc * 100, c.csprc, c.slprc, a.QTY, kcje = a.qty * c.csprc, b.slqty, slamt = b.slqty * c.slprc, zck = d.ckqty FROM (SELECT pluid = a.pluid, pluno = a.pluno, pluname = a.pluname, csprc = b.avgcsprc, slprc = b.slprc FROM basplumain a, baspluprc b WHERE a.pluid = b.pluid AND a.pluno LIKE :PLUNO + '%' group by a.pluid) c JOIN (SELECT PLUID = a.pluid, QTY = SUM(a.BEGQTY + a.INQTY - a.OUTQTY) FROM FINSTOCKSHP a WHERE shpid = 2 GROUP BY pluid) a ON a.pluid = c.pluid LEFT JOIN (SELECT slQTY = SUM(QTY), pluid FROM FINEBK WHERE DOCTYP / 1000000 = 21 AND level3 = 0 AND docdat >= :BDAT AND docdat <= :EDAT GROUP BY pluid) b ON c.pluid = b.pluid LEFT JOIN (SELECT pluid, ckQTY = a.BEGQTY + a.INQTY - a.OUTQTY FROM (SELECT PLUID, BEGCS = SUM(BEGCS), BEGQTY = SUM(BEGQTY), INCS = SUM(INCS), INQTY = SUM(INQTY), OUTQTY = SUM(OUTQTY) FROM FINSTOCKSHP A WHERE a.shpid = 7 GROUP BY PLUID) A) d ON c.pluid = d .pluid
SELECT buhuo = CASE WHEN b.slqty > a.qty THEN '*' ELSE '' END, c.PLUno, c.pluname, c.pkunit, c.spec, mll = (c.slprc - c.csprc) / c.slprc * 100, c.csprc, c.slprc, a.QTY, kcje = a.qty * c.csprc, b.slqty, slamt = b.slqty * c.slprc, zck = d.ckqty FROM (SELECT pluid = a.pluid, pluno = a.pluno, pluname = a.pluname, spec = a.spec, pkunit = a.pkunit, csprc = b.avgcsprc, slprc = b.slprc FROM basplumain a, baspluprc b WHERE a.pluid = b.pluid AND a.pluno LIKE :PLUNO + '%' group by a.pluid) c JOIN (SELECT PLUID = a.pluid, QTY = SUM(a.BEGQTY + a.INQTY - a.OUTQTY) FROM FINSTOCKSHP a WHERE shpid = 2 GROUP BY pluid) a ON a.pluid = c.pluid LEFT JOIN (SELECT slQTY = SUM(QTY), pluid FROM FINEBK WHERE DOCTYP / 1000000 = 21 AND level3 = 0 AND docdat >= :BDAT AND docdat <= :EDAT GROUP BY pluid) b ON c.pluid = b.pluid LEFT JOIN (SELECT pluid, ckQTY = a.BEGQTY + a.INQTY - a.OUTQTY FROM (SELECT PLUID, BEGCS = SUM(BEGCS), BEGQTY = SUM(BEGQTY), INCS = SUM(INCS), INQTY = SUM(INQTY), OUTQTY = SUM(OUTQTY) FROM FINSTOCKSHP A WHERE a.shpid = 7 GROUP BY PLUID) A) d ON c.pluid = d .pluid