bZh*_*ang -2 sql database oracle
说我有一个sql,目前返回所有在每年玩过的足球运动员.像这样:
name year goals
john 2010 1
john 2006 2
john 2006 8
fred 2006 1
Run Code Online (Sandbox Code Playgroud)
但我希望结果按照他们玩的年份进行分组,但如果来自不同年份,则不要压缩玩家名称,如下所示:
name year goals
john 2010 1
john 2006 10 <--- This is compressed, but there are still 2 johns
fred 2006 1 since they are from different years
Run Code Online (Sandbox Code Playgroud)
说到目前为止我已经这样做了.
(select name, year, goals
from table) as T
Run Code Online (Sandbox Code Playgroud)
如果我这样做
select *
from
(select name, year, goals
from table) as T
group by year;
Run Code Online (Sandbox Code Playgroud)
弗雷德将消失,但如果我按"名字分组",只剩下一个约翰.有帮助吗?
select name, year, sum(goals) as totalgoals
from table
group by name, year
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
56 次 |
| 最近记录: |