从两列中选择?

时间:2012-04-25 11:15:22

标签: sql oracle10g

CREATE TABLE Player
(playerID CHAR(3) ,
name CHAR(36),
year NUMBER,
team CHAR(50),
totalNoms NUMBER,
awardsWon NUMBER)

如何创建一个查询,从数据库中选择两列(团队和队员)?

3 个答案:

答案 0 :(得分:2)

取决于你想要做什么

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

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

答案 1 :(得分:1)

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

enter image description here

答案 2 :(得分:0)

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

输出将是(例如):

  • Team1 25
  • Team2 34
  • Team3 11