-1


我想做两件事,但我被卡住了。

首先,我想写一个SQL语句来向我展示所有的运动和每项运动的所有比赛日。桌子Event看起来像这样

Competitor ID  sports   branch         distance   men's/women    
  1            Running  Long-Distance  50000        MEN          

我还有一个名为的表,EventDay其中包含CompetitorID、和。datearenaspectators

CompetitorID  Date       Arena      Spectators
1             08/11/11   Olympus    500

这里显然会有一个加入声明,但我无法让它工作。

在下表中,我想准确了解各个国家从田径分部获得的金牌数量。我还希望它按性别划分并按照国家名称排序。

Land         Sex           Ammount gold
USA           L                   2
USA           M                   4
Ryss          L                   3
Ryss          H                   2
4

3 回答 3

1

试试这个

SELECT  Country,Sex
,       sum(AmountGold) as TotalGold
FROM YourTable
GROUP BY 
        Country,Sex
ORDER BY 
        Country,Sex

我认为这就是你需要的

于 2013-09-11T09:12:56.363 回答
0
select  Country
,       Sex
,       sum(case when MedalType = 'Gold' then 1 else 0 end) as AmountGold
from    YourTable
group by
        Country
,       Sex
order by
        AmountGold desc
于 2013-09-11T09:02:53.233 回答
0

试试这个:

SELECT COUNTRY, 
       SUM(AMOUNT_GOLD) AS TOTAL_GOLD 
FROM   ATHLETICS 
GROUP  BY LAND, 
          SEX 
ORDER  BY LAND 
于 2013-09-11T09:25:03.103 回答