Saturday, February 25, 2012

max(x) and top n

hello

i need a select than return max of top 10

for example top 10 return

5-9-6-10-78-2

i need max of them

how can i use max(x) in top n?

Try it like this

SELECT MAX(column1)FROM (SELECT TOP 10 column1FROM myTableORDER BY column2)AS A
|||

Or

SELECTMAX(colA)AS maxColAFROM(SELECTROW_NUMBER()OVER(ORDERBY colBDESC)AS rownumber, ColAFROM yourTable)AS t1

WHERE rownumber<= 10

No comments:

Post a Comment