作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一张如下所示的表格:
date code name score set
09/09/12 967873 Team A 24 1
09/09/12 967873 Team B 22 1
09/09/12 967873 Team A 21 2
09/09/12 967873 Team B 16 2
02/04/12 965454 Team X 21 1
02/04/12 965454 Team Y 19 1
02/04/12 965454 Team X 21 2
02/04/12 965454 Team Y 19 2
date code Teams Set-1 Set-2 Set-3
09/09/12 967873 Team A VS.Team B 24-22 21-16 -
and so on....
**Notice that the game could have a third set as well
最佳答案
查询可能如下所示:
with matches as (
select "DATE", code, name,
max(case when "SET" = 1 then score end) score_1,
max(case when "SET" = 2 then score end) score_2,
max(case when "SET" = 3 then score end) score_3,
row_number() over(partition by "DATE", code order by name) team_no
from games
group by "DATE", code, name
)
select a."DATE", a.code, a.name || ' vs. ' || b.name teams,
a.score_1 || '-' || b.score_1 set_1,
a.score_2 || '-' || b.score_2 set_2,
a.score_3 || '-' || b.score_3 set_3
from matches a
join matches b on a."DATE" = b."DATE" and a.code = b.code
where a.team_no = 1 and b.team_no = 2;
关于sql - 甲骨文 11g : How to union an oracle table with itself?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13257632/
我是一名优秀的程序员,十分优秀!