下面是我的表數據多列上的Sql Server Max函數?
Mat Phy Chem
20 30 40
25 35 35
45 30 30
45 40 35
我要檢索單一行的所有三列前3位的最大行數。
O/P
Mat Phy Chem
45 40 40
25 35 35
20 30 30
我用下面的查詢,但不成功,請幫助...
Select distinct top 3 max(mat) from studata group by mat order by max(mat) desc
Union all
Select distinct top 3 max(phy) from studata group by phy order by max(phy) desc
Union all
Select distinct top 3 max(chem) from studata group by chem order by max(chem) desc
這肯定是矯枉過正? – 2011-03-31 14:39:35
我認爲你應該使用'DENSE_RANK'而不是'ROW_NUMBER',因爲op可以爲每列有相同的值,並且它不會檢索前3個不同的最大值。 – Lamak 2011-03-31 14:40:14
Quassnoi你awesomem它的工作原理 – Simhadri 2011-03-31 14:46:39