select max similar rows by numeric field for all users
we have table as below :
user 开发者_如何学C point
+-------+------+
| user1 | 6080 | // user1 has this value
+-------+------+
| user1 | 5300 |
+-------+------+
| user2 | 6080 | // user2 has this value
+-------+------+
| user3 | 6080 | // user3 has this value
+-------+------+
| user3 | 5300 |
+-------+------+
| user1 | 3520 |
+-------+------+
| user2 | 5300 |
+-------+------+
| user3 | 9800 |
i want to get the max similar value that all users
have at least one of that
in this sample there are two value that all users have. 6080
and 5300
result should be 6080
how can i do that ?
Would look like this. You need to limit the results to 1, so for example for mysql you should use limit 1 at the end or for mssql select top 1 point .. etc etc.
select point
from user
group by point
having count(*)=(select count(distinct user) from user)
order by point desc
SELECT point, count(*) AS cnt FROM table GROUP BY point ORDER BY cnt DESC LIMIT 1
精彩评论