![]() ![]() LEFT JOIN (SELECT Cust_ID, SUM(Qty) Qty FROM Amex GROUP BY Cust_ID) 2 ON 2.Cust_ID = c. LEFT JOIN (SELECT Cust_ID, SUM(Qty) Qty FROM MC GROUP BY Cust_ID) 1 ON 1.Cust_ID = c.Cust_ID If a Customer table exists in the database, then this can be simplified to: SELECT c.Cust_ID, (1.Qty+2.Qty) AS total_qty FROM Customer c A NUMBER columns width equals the width of the heading or the width of the FORMAT plus one space for the sign, whichever is greater.If you do not explicitly use FORMAT, then the columns width will always be at least the value of SET NUMWIDTH. The code would then look like this: SELECT COALESCE(1.Cust_ID, 2.Cust_ID) Cust_ID, (1.Qty+2.Qty) AS total_qtyįROM (SELECT Cust_ID, SUM(Qty) Qty FROM MC GROUP BY Cust_ID) 1įULL OUTER JOIN (SELECT Cust_ID, SUM(Qty) Qty FROM Amex GROUP BY Cust_ID) 2 ON 1.Cust_ID = 2.Cust_ID Let's say we have a Cust_ID on both MC and Amex to identify the customer which made each order, and we want to know the sums for each customer. ![]() Here's an example for if you wish to expand this out to include a Group By condition. ![]() If you wish to avoid using Union or Union ALL (probably for efficiency reasons), then the following works: SELECT (1.Qty+2.Qty) AS total_qty FROM (SELECT SUM(Qty) Qty FROM MC) 1, ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |