how to select all of duplicate record in mysql -


my records is:

name    |   id  |   avg(point) point       |   1   |   6 b       |   2   |   6 c       |   3   |   5 d       |   4   |   5 e       |   5   |   4 f       |   6   |   3 g       |   7   |   2 

how select record below:

1.i want select top 3 record, result follow:

name    |   id  |   avg(point) point       |   1   |   6 b       |   2   |   6 c       |   3   |   5 d       |   4   |   5 e       |   5   |   4 

2.i want select record not top 3, result follow:

name    |   id  |   avg(point) point f       |   6   |   3 g       |   7   |   2 

how can do?

there several ways these. here's couple using in , not in.

for top 3, can use in:

select *  yourtable  point in (select distinct point                  yourtable                  order 1 desc                  limit 3) 

for rest, use not in instead:

select *  yourtable  point not in (select distinct point                  yourtable                  order 1 desc                  limit 3) 

other methods include exists not exists , distinct joins.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -