我想创建一个存储过程,它接受球队名称和年份,并返回该特定球队在该特定年份的球员人数。我正在使用 MYSQL,下面列出了我正在使用的表:
Person (personID, name, phone, email, year)
Player (personID, dateOfBirth, school)
playerTeam (personID, teamID)
Team (teamID, teamName, ageGroup)
到目前为止,我已经尝试加入表格并仅在 teamName 和 Person.year = 输入参数的情况下计算 personID,但无济于事。有任何想法吗?
提交此问题后,通过反复试验,我能够使用以下语句使其工作:
DELIMITER //
CREATE PROCEDURE teamSize (IN team VARCHAR (30), IN YEAR INT)
BEGIN
SELECT
COUNT(Person.personID) NumOfPlayers
FROM
Person AS p,
Player,
playerTeam,
Team
WHERE Person.personID = Player.personID
AND Player.personID = playerTeam.personID
AND Team.teamID = playerTeam.teamID
AND Team.teamName = team
AND Person.year = YEAR ;
END //
DELIMITER ;
CALL teamSize('Pirates', 1991);
反正有没有使用连接等来简化这个,因为目前它有点混乱。