简体   繁体   中英

Get max() value from distinct row value sql server

I need to select max value for different rows by same column:

Here's my table

id          | visited_count
------------+--------------
01071400005 | 1
01071400005 | 5
01071400006 | 1
01071400006 | 3

I need to show 01071400005 and 01071400006, so I tried below code but it only selects 01071400005.

SELECT  MAX(visited_count) - 1 
from   tbl_all_purple_flag_level where id in 
(select distinct(id) from tbl_all_purple_flag_level ) 

How can I select both of them?

如果我正确理解,那么您只想按id对表进行分组

SELECT id, MAX(visited_count) FROM tbl_all_purple_flag_level GROUP BY id

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