检索mysql表中每个区域列的每个年龄组列的第一个和第二个最佳获胜结果



MySql问题:我想根据获胜情况提取每个区域的两个最佳年龄组。我在这方面运气不太好,浏览过类似的问题。这可能很简单,但mysql今晚对我来说不太好。

获胜52>>96//tr>
地区 年龄组
伦敦 35
巴黎 10 54
都柏林 15 57
伦敦 40 65
巴黎 20 68
都柏林 35 73
巴黎 5 75
伦敦 5 79
都柏林 25 81
巴黎 15 81
伦敦 3082
都柏林 20 83
伦敦 20 85
伦敦 10 87
伦敦 25 87
巴黎 30 91
巴黎 25 91
都柏林 40 94
都柏林 3096
都柏林 5
伦敦 15 99
都柏林 10 100
select   region
,group_concat(case when dns_rnk = 1 then age_group end) as best_age_category
,group_concat(case when dns_rnk = 2 then age_group end) as second_best_age_category
from     (
select *
,dense_rank() over(partition by region order by wins desc) as dns_rnk
from   t
) t
group by region
5.30
区域最佳_类别第二_最佳_类别
都柏林10
伦敦1525,10
巴黎30,2515

使用ROW_NUMBER((OVER(<partition_definition><order_definition>(为记录分配行号,然后筛选行号为1或2 的位置

相关内容

最新更新