Home > database >  Using SQL SUM SUM of data errors
Using SQL SUM SUM of data errors

Time:09-25

Using the following syntax queries to the sum of the data is correct and some is wrong, please you master some directions

SELECT OR01001 AS [sales order], OR03005 AS [material], OR03002 AS [line number], OR01072 AS [customer order number], SC01060 AS [customer product code], SL01099 AS [shipping address], SL01194 AS [] the goods warehouse, OR03011 AS order [number], the SUM (OR19007) AS number] [delivery, OR19011 AS/delivery date FROM OR01DP00 AS/sales order
LEFT the JOIN OR03DP00 ON OR01001=OR03001
LEFT the JOIN SC01DP00 ON OR03005=SC01001
LEFT the JOIN SC04DP00 ON OR03005=SC04001
LEFT the JOIN SL01DP00 ON OR01003=SL01001 AND OR03119=SL01001
LEFT the JOIN OR19DP00 ON OR03001=OR19001 AND OR03002=OR19002 AND OR03003=OR19003
WHERE OR01003='S105895 AND SC04002=' ST 'AND SC04003=' CHA '
GROUP BY OR01001 OR03005, OR03002 OR01072, SC01060, OR19011, SL01099, SL01194, OR03011
The UNION
SELECT OR20001 AS [sales order], OR21005 AS [material], OR21002 AS [line number], OR20072 AS [customer order number], SC01060 AS [customer product code], SL01099 AS [shipping address], SL01194 AS [] the goods warehouse, OR21011 AS order [number], the SUM (OR23007) AS number] [delivery, OR23011 AS/delivery date FROM OR20DP00 AS/sales order
LEFT the JOIN OR21DP00 ON OR20001=OR21001
LEFT the JOIN SC01DP00 ON OR21005=SC01001
LEFT the JOIN SC04DP00 ON OR21005=SC04001
LEFT the JOIN SL01DP00 ON OR20003=SL01001 AND OR21119=SL01001
LEFT the JOIN OR23DP00 ON OR21001=OR23001 AND OR21002=OR23002 AND OR21003=OR23003
WHERE OR20003='S105895 AND SC04002=' ST 'AND SC04003=' CHA '
GROUP BY OR20001 OR21005, OR21002 OR20072, SC01060, OR23011, SL01099, SL01194, OR21011

As shown in figure, the number "0011700537" to add the number of different date together, every day I am need to separate the total shipment quantity for each order

CodePudding user response:

Estimation is a problem of the UNION, it is recommended that the first UNION, another GROUP BY outside,

CodePudding user response:

What are you going to press/sales order, delivery date to Group By, and you want to display materials, a detailed line number, and requirements and is certainly not at the same time
  • Related