2

TWO TABLES

ORDER_TABLE:

ORDER_ID | TARGET_QTY | 
-----------------------
1        |    50     
2        |    100  
3        |    200

ALLOC_TABLE:

ORDER_ID | TARGET_QTY |
-----------------------
1        |         50  
2        |         20  
2        |         30  
3        |        200  

I want to return ORDER_TABLE.ORDER_ID's where the SUM(ALLOC_TABLE.TARGET_QTY) for an order ID is < ORDER_TABLE.TARGET_QTY. Ex. of desired output below:

ORDER_ID | 
---------
2

All help is appreciated!

2 Answers 2

2
SELECT
at.ORDER_ID
FROM
    ALLOC_TABLE at
    JOIN ORDER_TABLE ot ON at.ORDER_ID = ot.ORDER_ID
GROUP BY
    at.ORDER_ID, ot.TARGET_QTY
HAVING
    SUM(at.TARGET_QTY) < ot.TARGET_QTY
Sign up to request clarification or add additional context in comments.

Comments

0

try this pls

SELECT  at.ORDER_ID
FROM   ALLOC_TABLE at
full outer JOIN ORDER_TABLE ot ON at.ORDER_ID = ot.ORDER_ID
GROUP BY at.ORDER_ID
HAVING SUM(at.TARGET_QTY) < ot.TARGET_QTY

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.