【发布时间】:2022-11-20 04:18:51
【问题描述】:
我有一个问题,我想计算一个国家从个人和团体比赛中总共赢得了多少奖牌,这并不能给我带来不利的结果。到目前为止我已经设法想出了这个。
select distinct C.Cname as Country, count(i.medal) as Medals_Won
from individual_results as i, Country as C, participant as p
where (i.Olympian = p.OlympicID and C.Cname = p.country)
union
select distinct C.Cname, count(r.medal) as medals_Won
from team_results as r, Country as C, participant as p, team as t
where (r.team = t.TeamID and t.Member1 = p.OlympicID and C.Cname = p.Country)
group by C.Cname
order by medals_won desc
但我得到了这个结果。
即使我运行这两段单独的代码,我也会得到想要的结果,即enter image description here
【问题讨论】: