您可以根據您需要的值獲得計數(distcint id)。例如。對於這兩個值:
select count(distinct id), highest_item, highest_level
from (
SELECT id,
MAX(item) AS highest_item,
MAX(level) AS highest_item
FROM data
GROUP BY 1
) t
group by highest_item, highest_level
order by count(distinct id) desc
或highest_item
select count(distinct id), highest_item
from (
SELECT id
MAX(item) AS highest_item,
MAX(level) AS highest_level
FROM data
GROUP BY 1
) t
group by highest_item
order by count(distinct id) desc
的
爲HIGHEST_LEVEL
select count(distinct id), highest_level
from (
SELECT id,
MAX(item) AS highest_item,
MAX(level) AS highest_level
FROM data
GROUP BY 1
) t
group by highest_level
order by count(distinct id) desc
利用你的第一個建議,組我得到一個簡單計數的結果表,其中不是我所需要的,我需要一個包含關卡#,項目ID和有多少不同用戶與同一項目處於同一級別的表。你能否在你的查詢中解釋「t」字符的用途? – nyvokub
添加了關卡...... t是()t ..子查詢的表名,但是用戶與問題的關係如何(我假設你是meadn是這個id的數目)。我在查詢中沒有看到任何用戶列。 – scaisEdge