2012-04-25 57 views
-1
CREATE TABLE Player 
(playerID CHAR(3) , 
name CHAR(36), 
year NUMBER, 
team CHAR(50), 
totalNoms NUMBER, 
awardsWon NUMBER) 

如何创建一个查询,以便从数据库的两列(团队和玩家数量)中进行选择?从两列中选择?

+0

不知道如果我明白你的问题,是 “没有的球员”,在表中 “播放器” 的列?如果不是,请指定包含此列的表格。如果是(我不假设)指定它是哪一列。 – FrankE 2012-04-25 11:19:31

回答

0
Select distinct p.team, (
Select count(*) from Player where team=p.team 
) 
from Player p 

输出会是什么(例如):

  • TEAM1 25
  • 的Team2 34
  • Team3 11
2

取决于你愿意,你可以做

select team, count(PlayerID) as NoOfPlayers 
from Player 
where team = 'Lackers' 

select team, count(PlayerID) as NoOfPlayers 
from Player 
group by team 
+0

难道你错过了“GROUP BY团队”吗? – Arion 2012-04-25 11:22:19

+0

@Arion:不确定OP想要什么。也许你是对的。 – 2012-04-25 11:25:24

1
SELECT team,COUNT(playerID) As NoOfPlayers from Player group by team 

enter image description here