Groups | Blog | Home
all groups > sql server new users > december 2005 >

sql server new users : Simple Select ?


Vishal
12/25/2005 1:13:04 AM
Hi,

I have one Table which has Sales for 5 Year, the structure is as follows
Store ID INT
Year INT
Month INT
SALES MONEY

Is it possible to get the sales for Feb 2004 & Feb 2005 in a single query ?

Something like this
Store ID Year Month Sales
1 2005 8 5000
1 2004 8 3000

This may be a stupid question but I am newbie.

Thank you


Andrew J. Kelly
12/25/2005 10:04:12 AM
SELECT StoredID, [Year], [Month] SUM(Sales) AS [Sales]
FROM YourTable
GROUP BY StoredID, [Year],[Month]

--
Andrew J. Kelly SQL MVP


[quoted text, click to view]

Lawrence Garvin
12/27/2005 10:46:11 AM

Would Vishal also want a WHERE clause in that query, to restrict the result
set to just the two desired months?

[quoted text, click to view]


[quoted text, click to view]

Andrew J. Kelly
12/27/2005 1:26:15 PM
Only he knows that. I would hope he would have a WHERE clause but I am not
going to guess what it should be<g>.

--
Andrew J. Kelly SQL MVP


[quoted text, click to view]

Lawrence Garvin
12/28/2005 9:29:35 AM
Only reason I responded was because he asked specifically about getting same
month sales in consecutive years. I thought perhaps it was a question more
about selection logic rather than aggregation.

[quoted text, click to view]

Andrew J. Kelly
12/28/2005 11:08:41 AM
Oh I see now. Maybe you are right but I figured that would be the easy part.

--
Andrew J. Kelly SQL MVP


[quoted text, click to view]

AddThis Social Bookmark Button