select name,
max(case when year=2008 then run end) as year_2008,
max(case when year=2009 then run end) as year_2009,
... and so on
from my_table
group by name;
select
sum(case when year=2008 then run else 0 end) 2008_run,
sum(case when year=2009 then run else 0 end) 2009_run,
from table t1
group by name;
每年找出前五名得分手。
with table1 as
(
select name, sum(runs) as RunsPerYear, year from myTable group by name, year
)
table2 as
(
select name, year, RunsPerYear, dense_rank() over (partition by name, year order by RunsPerYear) as rnk from table2
)
select name, year, RunsPerYear from table2 where rnk<=5;
2条答案
按热度按时间hgb9j2n61#
固定年份:
在配置单元中不可能动态生成这样的列,但是您可以先选择不同的年份,然后使用shell生成这个sql。
57hvy0tb2#
根据我的理解,你需要把每年的一些跑步数据转换成年份栏
你需要求和函数,而不是max
每年找出前五名得分手。