1

How can I make this select the 7500 or greater from the ON_HAND VALUE column?

" List the part number part descrtiption and onhand value for each part whose on hand value is at least $7,500. Assign ON_HAND_VALUES as the computed column."

This is what I have so far, I tried subquerys IN statements but I cant figure it out.

SELECT PART_NUM, DESCRIPTION, SUM(ON_HAND * PRICE) AS ON_HAND_VALUE
FROM PART
WHERE SUM(ON_HAND * PRICE)'7500'
GROUP BY PART_NUM, DESCRIPTION;

Part Table

PART_NUM    DESCRIPTION     ON_HAND     CLASS   WAREHOUSE   PRICE

AT94       Iron               50         HW         3       24.95
BV06       Home Gym           45         SG         2       794.95
CD52       Microwave Oven     32        AP          1       165.00
DL71       Cordless Drill     21        HW          3       129.95
DR93       Gas Range           8        AP          2       495.00
DW11       Washer             12        AP          3       399.99
FD21       Stand Mixer        22        HW          3       159.95
KL62       Dryer              12        AP          1       349.95
KT03       Dishwasher          8        AP          3       595.00
KV29       Treadmill           9        SG          2       1390.00

3 Answers 3

2

you can't use where, you have to use having with aggregate functions:

SELECT PART_NUM, DESCRIPTION, SUM(ON_HAND * PRICE) AS ON_HAND_VALUE
FROM PART
GROUP BY PART_NUM, DESCRIPTION;
HAVING SUM(ON_HAND * PRICE)'7500'

where is evaluated before grouping and summing happens, having evaluates on the result set, after records are filtered and grouped

Sign up to request clarification or add additional context in comments.

Comments

0

This is what I used.

SELECT PART_NUM, DESCRIPTION, SUM(ON_HAND * PRICE) AS ON_HAND_VALUE
FROM PART
GROUP BY PART_NUM
HAVING SUM(ON_HAND * PRICE)  > '7500'
ORDER BY PART_NUM;

Comments

0

The first two people are wrong. I know for a fact this is correct:

SELECT PART_NUM, DESCRIPTION, (ON_HAND * PRICE) AS ON_HAND_VALUE
FROM PART
WHERE (ON_HAND * PRICE) >= 7500

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.