开发者

Most common value for multiple fields

开发者 https://www.devze.com 2022-12-16 10:23 出处:网络
I开发者_如何转开发 have a table which contains ratings. Included with the rating is data the user provided such as the language that the linked series belongs to.

I开发者_如何转开发 have a table which contains ratings. Included with the rating is data the user provided such as the language that the linked series belongs to.

id  series_id  language  quality  type  rating
1   18         1         2        1     20
2   18         2         3        2     13
3   18         1         1        2     25
4   18         1         3        5     8
5   18         3         1        1     17
6   18         3         3        2     9

What would be the best way to find the most common value for language, quality and type, for a certain series_id?

In other words, if I was looking at series 18, it would return the following as those numbers occur the most.

language: 1
quality:  3
type:     2


It's probably easiest to do it as three separate SELECT statements:

SELECT language
FROM MyTable
WHERE series_id = 18
GROUP BY language
ORDER BY COUNT(*) DESC LIMIT 1

SELECT quality
FROM MyTable
WHERE series_id = 18
GROUP BY quality
ORDER BY COUNT(*) DESC LIMIT 1

SELECT type
FROM MyTable
WHERE series_id = 18
GROUP BY type
ORDER BY COUNT(*) DESC LIMIT 1
0

精彩评论

暂无评论...
验证码 换一张
取 消