简体   繁体   中英

MySQL Group By with Distinct

I have a dynamic table (from subquery):

col1 | col2
-----------
 14  | 1000
 14  | 2000
 14  | 3000
 15  | 1000
 15  | 2000

I want to group result by col1, but with distinct col2 value:

col1 | col2
-----------
 14  | 1000
 15  | 2000

Is it possible?

additional info :

  • col2 is ordered by ASC
  • col1 values is not important, can be removed from result table
  • number of rows = number of col1 unique values

请尝试以下一项:

select DISTINCT(col2), col1 from tablename group by col1

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