tags:

views:

28

answers:

3

I need to fix this query so that it will give me the part number, part description and on hand value for each part in the SG class. This is what I have so far. but it just gives me the total value of all the items in the SG class. How can I have it where it will give me the total based on the description?

SELECT PART_NUM, DESCRIPTION, SUM(ON_HAND * PRICE) AS ON_HAND_VALUE
FROM PART
WHERE CLASS = 'SG'

PART_NUM    DESCRIPTION     ON_HAND_VALUE
BV06          Home Gym         48282.75

Part Table "All the items in the SG class"

PART_NUM    DESCRIPTION     ON_HAND     CLASS   WAREHOUSE   PRICE
    BV06       Home Gym       45          SG         2      794.95
    KV29       Treadmill       9          SG         2      1390.00
A: 

Add..

Group By Part_Num, Description

DRapp
+1  A: 

How can I have it where it will give me the total based on the description?

Add the Group By clause

SELECT PART_NUM, DESCRIPTION, SUM(ON_HAND * PRICE) AS ON_HAND_VALUE
FROM PART
WHERE CLASS = 'SG'
GROUP BY DESCRIPTION
SDReyes
A: 

Worked Great thanks guys

Michael Quiles
You're welcome. please accept (the 'V' symbol below the answer counter) the @DRapp answer and vote up him : )
SDReyes
As you are new to the forum, its good manners to click the checkbox next to the answer that was used to solve your solution... for future of others looking into similar problems. Additionally, when querying with Aggregates ( sum(), min(), max(), etc), you TYPICALLY need a group by of all NON-AGGREGATE columns, hence I include the group by part number AND description.
DRapp
This isn't an answer. Post it as a comment to the answer you are referring to.
Mark Byers