SELECT SPXX.SPXX_SPBH, SPXX.SPXX_SPQM, SPXX.SPXX_XH, SPXX.SPXX_GG, SPXX.SPXX_CD,
SPXX.SPXX_DW, SPXX.SPXX_FZDW, SPXX.SPXX_DWGX,(jh.jhsl - th.thsl) as '数量'
FROM (SELECT JHMXB.SPBH as bh, JHMXB.SPQM, SUM(JHMXB.SL) as jhsl
FROM JHMXB, JHDDB
WHERE JHMXB.DJBH = JHDDB.DJBH
GROUP BY JHMXB.SPBH, JHMXB.SPQM) as jh join SPXX on jh.bh = SPXX.SPXX_SPBH join (SELECT
JHTHMXB.SPBH as bh, JHTHMXB.SPQM, SUM(JHTHMXB.SL) as thsl
FROM JHTHDB, JHTHMXB
WHERE JHTHDB.BH = JHTHMXB.BH
GROUP BY JHTHMXB.SPBH, JHTHMXB.SPQM) as th on th.bh = SPXX.SPXX_SPBH
上面是我一半的SQL语句,如果写完的话,也太长了。。。。 |