all groups > sql server new users > december 2005 >
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
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] "Vishal" <vrajput77@hotmail.com> wrote in message news:uPXyqNTCGHA.2356@tk2msftngp13.phx.gbl... > 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 > > >
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] > SELECT StoredID, [Year], [Month] SUM(Sales) AS [Sales] > FROM YourTable WHERE [Month] = 8 AND ([Year] = 2004 OR [Year] = 2005) > GROUP BY StoredID, [Year],[Month]
[quoted text, click to view] "Andrew J. Kelly" <sqlmvpnooospam@shadhawk.com> wrote in message news:ekpn4RWCGHA.516@TK2MSFTNGP15.phx.gbl... > SELECT StoredID, [Year], [Month] SUM(Sales) AS [Sales] > FROM YourTable > GROUP BY StoredID, [Year],[Month] > > -- > Andrew J. Kelly SQL MVP > > > "Vishal" <vrajput77@hotmail.com> wrote in message > news:uPXyqNTCGHA.2356@tk2msftngp13.phx.gbl... >> 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 >> >> >> > >
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" <onsitech@news.postalias> wrote in message news:eQrZMUwCGHA.740@TK2MSFTNGP12.phx.gbl... > > Would Vishal also want a WHERE clause in that query, to restrict the > result set to just the two desired months? > >> SELECT StoredID, [Year], [Month] SUM(Sales) AS [Sales] >> FROM YourTable > WHERE [Month] = 8 AND ([Year] = 2004 OR [Year] = 2005) >> GROUP BY StoredID, [Year],[Month] > > > "Andrew J. Kelly" <sqlmvpnooospam@shadhawk.com> wrote in message > news:ekpn4RWCGHA.516@TK2MSFTNGP15.phx.gbl... >> SELECT StoredID, [Year], [Month] SUM(Sales) AS [Sales] >> FROM YourTable >> GROUP BY StoredID, [Year],[Month] >> >> -- >> Andrew J. Kelly SQL MVP >> >> >> "Vishal" <vrajput77@hotmail.com> wrote in message >> news:uPXyqNTCGHA.2356@tk2msftngp13.phx.gbl... >>> 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 >>> >>> >>> >> >> > >
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" <sqlmvpnooospam@shadhawk.com> wrote in message news:OmACLRxCGHA.2704@TK2MSFTNGP11.phx.gbl... > 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 > > > "Lawrence Garvin" <onsitech@news.postalias> wrote in message > news:eQrZMUwCGHA.740@TK2MSFTNGP12.phx.gbl... >> >> Would Vishal also want a WHERE clause in that query, to restrict the >> result set to just the two desired months? >> >>> SELECT StoredID, [Year], [Month] SUM(Sales) AS [Sales] >>> FROM YourTable >> WHERE [Month] = 8 AND ([Year] = 2004 OR [Year] = 2005) >>> GROUP BY StoredID, [Year],[Month] >> >> >> "Andrew J. Kelly" <sqlmvpnooospam@shadhawk.com> wrote in message >> news:ekpn4RWCGHA.516@TK2MSFTNGP15.phx.gbl... >>> SELECT StoredID, [Year], [Month] SUM(Sales) AS [Sales] >>> FROM YourTable >>> GROUP BY StoredID, [Year],[Month] >>> >>> -- >>> Andrew J. Kelly SQL MVP >>> >>> >>> "Vishal" <vrajput77@hotmail.com> wrote in message >>> news:uPXyqNTCGHA.2356@tk2msftngp13.phx.gbl... >>>> 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 >>>> >>>> >>>> >>> >>> >> >> > >
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] "Lawrence Garvin" <onsitech@news.postalias> wrote in message news:OHvGDO8CGHA.4080@TK2MSFTNGP09.phx.gbl... > 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. > > "Andrew J. Kelly" <sqlmvpnooospam@shadhawk.com> wrote in message > news:OmACLRxCGHA.2704@TK2MSFTNGP11.phx.gbl... >> 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 >> >> >> "Lawrence Garvin" <onsitech@news.postalias> wrote in message >> news:eQrZMUwCGHA.740@TK2MSFTNGP12.phx.gbl... >>> >>> Would Vishal also want a WHERE clause in that query, to restrict the >>> result set to just the two desired months? >>> >>>> SELECT StoredID, [Year], [Month] SUM(Sales) AS [Sales] >>>> FROM YourTable >>> WHERE [Month] = 8 AND ([Year] = 2004 OR [Year] = 2005) >>>> GROUP BY StoredID, [Year],[Month] >>> >>> >>> "Andrew J. Kelly" <sqlmvpnooospam@shadhawk.com> wrote in message >>> news:ekpn4RWCGHA.516@TK2MSFTNGP15.phx.gbl... >>>> SELECT StoredID, [Year], [Month] SUM(Sales) AS [Sales] >>>> FROM YourTable >>>> GROUP BY StoredID, [Year],[Month] >>>> >>>> -- >>>> Andrew J. Kelly SQL MVP >>>> >>>> >>>> "Vishal" <vrajput77@hotmail.com> wrote in message >>>> news:uPXyqNTCGHA.2356@tk2msftngp13.phx.gbl... >>>>> 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 >>>>> >>>>> >>>>> >>>> >>>> >>> >>> >> >> > >
Don't see what you're looking for? Try a search.
|
|
|