Reputation: 2388
Working on a SQL query here, I have an ID column that I created and I want to be able to take the max ID number and show the 12 behind it. See picture. I want to show Row 20-8 and everything above 8, dismiss. Can someone help me with an orderby or between statement?
Thanks
my sql query:
SELECT TOP (100) PERCENT ROW_NUMBER() OVER (ORDER BY FiscalYear, FiscalMonth) as ID,FiscalYear, FiscalMonth, SUM(STDCOST) AS STDCost, Concat FROM dbo.[13568] GROUP BY FiscalYear, FiscalMonth, Concat ORDER BY FiscalYear, FiscalMonth
Upvotes: 0
Views: 216
Reputation: 89661
Am I missing something?
SELECT * FROM (
SELECT TOP 13 ROW_NUMBER() OVER (ORDER BY FiscalYear, FiscalMonth) as ID
,FiscalYear
,FiscalMonth
,SUM(STDCOST) AS STDCost
,Concat
FROM dbo.[13568]
GROUP BY FiscalYear, FiscalMonth, Concat
ORDER BY FiscalYear DESC, FiscalMonth DESC
) AS X
ORDER BY FiscalYear, FiscalMonth
Upvotes: 1