2012-04-25 60 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