开发者

Query using SUM

开发者 https://www.devze.com 2022-12-28 14:29 出处:网络
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

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 d开发者_如何转开发escription?

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


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


Add..

Group By Part_Num, Description

0

精彩评论

暂无评论...
验证码 换一张
取 消