Home > database >  Multiple table joins the SQL statement
Multiple table joins the SQL statement

Time:03-29

Now have such a SQL statement
 SELECT * FROM (SELECT MCODE, STORAGEID, SUM (STORAGEQTY) AS QTY 
The FROM TBLSTORAGEINFO
WHERE STORAGEQTY!=0
GROUP BY MCODE, STORAGEID) A
INNER JOIN (SELECT c. CODE, c.s. TORAGEID, SUM (C.L OTQTY) AS QTY
The FROM TBLSTORAGELOTINFO c
Inner join tblitemlot D
ON D.L OTNO=C.L OTNO
WHERE STORAGEID NOT LIKE '% GB %'
GROUP BY c. CODE, c.s. TORAGEID) B
ON arjun CODE=B.M CODE
AND A.S TORAGEID=B.S TORAGEID
AND A.Q TY!=B.Q TY

Results the following


Now need more connecting two tables
A XITEM KANZANK have A conversion coefficient in the table, when A and B MCODE=XITEM CODE, A.Q TY and B.Q TY need divided by KANZANK
HOKAN XZAIK another table, there are two fields and ZAIK HOKAN also need NOT LIKE '% GB %' ZAIK also needs to be divided by KANZANK
Hope XAIK CODE, in the result table HOKAN, ZAIK also add
Hope to get the following results now
MCODE STORAGEID QTY MCODE STORAGEID QTY CODE HOKAN ZAIK
1, 8021740 (I) BS02 8.5 8021740 8.505 8021740 (I) (I) BS02 BS02 8.5
2 (I) 5518010 8812 5518010 8632 5518010 (I) BS02 BS02 (I) BS02 8812

Probably is the case, I'm not very clear, the expression of ourselves are going to be around dizzy

CodePudding user response:

No direct relevance in, like this

 
SELECT * FROM (SELECT MCODE, STORAGEID, SUM (STORAGEQTY) AS QTY
The FROM TBLSTORAGEINFO
WHERE STORAGEQTY!=0
GROUP BY MCODE, STORAGEID) A
INNER JOIN (SELECT c. CODE, c.s. TORAGEID, SUM (C.L OTQTY) AS QTY
The FROM TBLSTORAGELOTINFO c
Inner join tblitemlot D
ON D.L OTNO=C.L OTNO
WHERE STORAGEID NOT LIKE '% GB %'
GROUP BY c. CODE, c.s. TORAGEID) B
ON arjun CODE=B.M CODE
AND A.S TORAGEID=B.S TORAGEID
AND A.Q TY!=B.Q TY
INNER JOIN XITEM E ON arjun CODE=the ODE of e.c. with our fabrication:
INNER JOIN XZAIK ON ODE of e.c. with our fabrication: F=f. ODE
WHERE HOKAN NOT LIKE '% GB %'
  • Related