Michael Quiles
Michael Quiles

Reputation: 1151

Query using SUM

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

Upvotes: 0

Views: 64

Answers (2)

SDReyes
SDReyes

Reputation: 9954

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

Upvotes: 1

DRapp
DRapp

Reputation: 48179

Add..

Group By Part_Num, Description

Upvotes: 0

Related Questions