-4

选手表:

player_ID
player_name
position_id

职位表:

position_ID
position_description

团队表:

TEAM_ID
TEAM_NAME

游戏桌:

Game_id
home_team_id
guest_team_id
score
location
date

统计表

game_id
player_id
number of fouls
number of rebounds

我尝试了以下查询来查找玩家可以在他们身上打的各种位置:

select  player.player_name,position.position_name
from player,position
where player.fname='John' and position_name='Guard,Midfield,Striker'

我尝试了以下查询来列出例如 5 次犯规的比赛日期和地点,我尝试了这个查询:

select game.date,location,number of fouls, 
from game,stats
where game.date=game.id
 and game.location=game.id
 and number of fouls > 5
group by game.date,game.location
4

1 回答 1

0

至少这是一个开始,但首先有几点:

  1. 我会避免使用空格的列名。如果您使用反引号,MySQL 将处理它们,但我发现它们比它们的价值更麻烦。

  2. 这些不是非常困难的查询。如果你有机会,花一个小时左右的时间做一个基本的 MySQL 教程。MySQL 站点有一些示例。

  3. 当您从两个或多个表中进行选择时,您几乎总是想要JOIN它们。教程将涵盖这一点。

好的,这里是查询...

球员和他们可以打的位置:

SELECT
  Player.Player_ID,
  Player.Player_Name,
  Position.Position_Description
FROM Player
INNER JOIN Position ON Player.Position_ID = Position.Position_ID
WHERE Player.FName = 'John'
  AND Position_Name IN ('Guard', 'Midfield', 'Striker')

犯规超过 5 次的比赛:

SELECT
  Game.Date,
  Game.Location,
  SUM(Stats.`number of fouls`) AS TotalFouls
FROM Game
INNER JOIN Stats ON Game.Game_ID = Stats.Game_ID
GROUP BY Game.Date, Game.Location
HAVING SUM(Stats.`number of fouls`) > 5
于 2013-05-02T17:22:00.920 回答