3
A
回答
10
是否這樣?
設置:
declare @MyTable table(Year int, Month int, Day int, Total int)
insert @MyTable
values
(2005, 9, 23, 12),
(2005, 9, 26, 5),
(2005, 9, 24, 1),
(2005, 9, 15, 28),
(2005, 9, 21, 1),
(2005, 9, 13, 1),
(2005, 10, 31, 5),
(2005, 11, 18, 115),
(2005, 11, 20, 1),
(2005, 11, 11, 1),
(2005, 11, 19, 1)
查詢:
;with cte
as
(
select *,
row_number() over(partition by Year, Month order by Total desc) RowNumber
from @MyTable
)
select Year, Month, Day, Total
from cte
where RowNumber = 1
輸出:
Year Month Day Total
----------- ----------- ----------- -----------
2005 9 15 28
2005 10 31 5
2005 11 18 115
+2
完美!非常感謝!!你在6分鐘內投票給你 – GayanSanjeewa 2011-06-16 04:05:28
相關問題
- 1. SQL Server 2008與SQL Server 2008 Express大小
- 2. Sql server 2008與servlet
- 3. ISNULL與SQL Server 2008
- 4. Android與SQL Server 2008
- 5. Sonar與SQL Server 2008
- 6. 的SQL Server 2008與SQL Server 2005
- 7. 獲取SQL Server 2008中的列狀態
- 8. 的SQL Server 2008與DATETIME2
- 9. 從Sql Server 2008獲取數據與C#
- 10. 同步sql server 2000與sql server 2008
- 11. 的SQL Server 2008 - 積累列
- 12. SQL SERVER 2008的另一列
- 13. SQL Server 2008的Sharepoint列表
- 14. Redmine與SQL Server 2008 R2
- 15. 子串與SQL Server 2008
- 16. 與SQL Server VBA形式2008
- 17. Rails與SQL Server 2008/2012 - FILESTREAM
- 18. SQL Server Express 2008與Management Studio
- 19. SQL Server Compact與Visual Studio 2008
- 20. C#複製 '\' 與SQL Server 2008
- 21. Concat NULL與Varchar SQL Server 2008
- 22. IIS6不能與SQL Server 2008
- 23. SQL Server 2008 - 觸發不讀取列名與空格
- 24. 從SQL Server 2008 RTF提取
- 25. 如何獲得SQL Server 2008中列值爲NULL的列名稱
- 26. SQL Server 2008列大小
- 27. SQL Server 2008列加密
- 28. 列索引在SQL Server 2008
- 29. SQL Server 2008中 - 計算列
- 30. 排列在SQL Server 2008
你怎麼要處理,其中最大值爲兩天共享幾個月? – geofftnz 2011-06-16 03:56:36
[SQL - 獲取具有列的最大值的行]的可能重複(http://stackoverflow.com/questions/121387/sql-fetch-the-row-which-has-the-max-value- for-a-column) – 2011-06-16 03:57:55