如何在 Oracle Developer 中使用 Count 功能

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4141837/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 21:53:46  来源:igfitidea点击:

How to utilize Count function in Oracle Developer

sqloracle

提问by Jeff

Ok so I'm working on my homework and am having trouble getting the Count function to work correctly.

好的,所以我正在做我的家庭作业并且无法让 Count 函数正常工作。

I am supposed to use "A query that lists all teams that have more than 4 players (in the players table). Include the columns team_id, team_name, and the count of players for that team."

我应该使用“一个查询,列出所有拥有超过 4 名球员的球队(在球员表中)。包括列 team_id、team_name 和该球队的球员人数。”

It is just a simple NHL database our teacher made up for this assignment. There are 18 teams in the teams database and 74 players in the players database.

这只是我们老师为这项作业制作的一个简单的 NHL 数据库。球队数据库中有18支球队,球员数据库中有74名球员。

This is what I have written as of right now:

这是我现在写的:

SELECT teams.team_id, teams.team_name, COUNT(players.team_id) AS PlayerCount 
FROM teams, players
GROUP BY teams.team_id, teams.team_name
HAVING COUNT(players.team_id) > 4;

And when I run that this is the output I get:

当我运行时,这是我得到的输出:

TEAM_ID TEAM_NAME                           PLAYERCOUNT            
------- ----------------------------------- ---------------------- 
TBL     Tampa Bay Lightening                74                     
BOS     Bostong Bruins                      74                     
SJS     San Jose Sharks                     74                     
NYI     New York Islanders                  74                     
MIN     Minnesota Wild                      74                     
DET     Detroit Red Wings                   74                     
NYR     New York Rangers                    74                     
PHL     Philadelphia Flyers                 74                     
BUF     Buffalo Bruins                      74                     
PIT     Pittsburgh Penguins                 74                     
DAL     Dallas Stars                        74                     
VAN     Vancouver Canucks                   74                     
WSH     Washington Capitals                 74                     
COL     Colorado Avalanche                  74                     
TOR     Toronto Maple Leafs                 74                     
CLB     Columbus Blue Hymanets               74                     
CHI     Chicago Blackhawks                  74                     
ATL     Atlanta Thrashers                   74                     

18 rows selected

I know it's probably pretty simple to fix, but I can't find anything that's like that in my textbook and the Google results I get are either not the same thing or more sophisticated than what I am trying to do.

我知道修复它可能很简单,但我在我的教科书中找不到任何类似的东西,而且我得到的谷歌结果要么不一样,要么比我想要做的更复杂。

Any help is greatly appreciated.

任何帮助是极大的赞赏。

回答by Jeffrey Kemp

You're doing a cartesian join between the tables.

您正在表之间进行笛卡尔连接。

SELECT teams.team_id, teams.team_name, COUNT(*) AS PlayerCount 
FROM teams, players
WHERE teams.team_id = players.team_id
GROUP BY teams.team_id, teams.team_name
HAVING COUNT(*) > 4;