Link to home
Start Free TrialLog in
Avatar of wilflife
wilflife

asked on

SQL

Hi,

I have a table with about 10 columns

Product
Country
Date     In text format JAN-09
Week Number
Product SubCategory
Product Description
Unit measure.
Units Sold
Vol Sold

I would like to do two things...

Aggregate up all the sales by summing units sold for each month
And also sum up the volume sold.
This should be returned by the same query.

All the other columns should be brought across with no calcs ie the units and this suming should be done at the month level so i have to split the month off from the string as well.

Thanks for help...
Avatar of jaanth
jaanth

What you are looking for is the sum function, which requires a group by clause on a select statement.
Since you want months, you will need to drop the week field from your query.

select
Product,
Country,
Product SubCategory,
Product Description,
Unit measure.
Date,                   --     In text format JAN-09
UnitsSold = sum(Units Sold),
VolSold = sum(Vol Sold)
from tablename1
group by
Product,
Country,
Product SubCategory,
Product Description,
Unit measure.
Date

Hope this helps.

Avatar of wilflife

ASKER

Will this give me it all grouped by the month.... as i know when i use the sum i have to group by everything but effectively i only want it grouped by the month and all other columns simply transported across... will this simple sql do it?

Thanks.
SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial