问题描述:

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
相关阅读:
Top