简体   繁体   中英

Selecting three of Max() values of a field in sql server

Assume that i have three field in my database like this :

ID    Title    MaxVisited

 1     hi          6
 2     bye         8
 3     How?        9
 4     News!       8
 5     Hey         3
 6     Thanks      9

now i want to select Title three of max value of MaxVisited.. the result which i want:

Thanks , How? , News!

Just select the top 3 and order by MaxVisited and (if necessary) the Id column

SELECT TOP 3 Title from [TableName] 
order by MaxVisited, Id desc

Try this

SELECT TOP 3 Title 
From [TableName] 
order by MaxVisited,Title desc
SELECT TOP 3 Title from [your_table] 
order by MaxVisited, ID desc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM