求一出库总数和出库明细表数量合计对不平的SQL--在线等! aa表(出库物料) number(id) name(物料名称) ckzs(出库总数) 1 A 5 2 B 0 3 C 11 4 D 0 bb表(出库明细) recnumber(出库物料ID) cksl(出库数量) 1 1 1 3 3 2 1 2 3 5 4 6
列出aa表中哪些物料出库总数和bb表出库明细数量合计对不起来的SQL语句
------解决方案--------------------
------解决方案--------------------
SQL code
CREATE TABLE TESTTB1(numberid INT ,name CHAR(5), ckzs INT)
INSERT TESTTB1
SELECT 1, 'A', 5 UNION
SELECT 2, 'B', 0 UNION
SELECT 3, 'C', 11 UNION
SELECT 4, 'D', 0
CREATE TABLE TESTTB2(recnumber INT,cksl INT)
INSERT TESTTB2
SELECT 1 , 1 UNION
SELECT 1 , 3 UNION
SELECT 3 , 2 UNION
SELECT 1 , 2 UNION
SELECT 3 , 5 UNION
SELECT 4 , 6
--SELECT * FROM TESTTB1
--SELECT * FROM TESTTB2
SELECT TESTTB1.* FROM TESTTB1,(SELECT RECNUMBER,SUM(CKSL)CKSL FROM TESTTB2 GROUP BY RECNUMBER)AS T
WHERE TESTTB1.numberid=T.RECNUMBER AND CKZS<>CKSL