0

我想从具有 HomeTeam 和 AwayTeam 字段的夹具表中获取俱乐部的夹具列表,但是当我搜索它时,它仅返回与搜索参数匹配的第一行。然而,当俱乐部在主场和客场比赛时,我想同时获得这两场比赛。这是我的程序

CREATE DEFINER=root@localhost PROCEDURE GetClubFixtures(clubName varchar(45))
BEGIN
SELECT FixtureDate, Tournament, HomeTeam, AwayTeam, KickOff
FROM  fixture
WHERE SeasonID in
(select SeasonID from season where seasonType=1) 
and HomeTeam = ClubName 
or AwayTeam=ClubName
ORDER BY FixtureDate;

只返回一行,如下图

'2013-05-15', 'FSL', 'Sports Club Victoria University', 'Villa Sports Club', 05:00:00

4

1 回答 1

0

基本上在您PROCEDURE使用的版本中

where SeasonID in
(select SeasonID from season where seasonType=1) 
and HomeTeam = ClubName 
or AwayTeam=ClubName

但我认为你想要的是这样的

where SeasonID in
(select SeasonID from season where seasonType=1) 
and 
(HomeTeam = ClubName 
or AwayTeam=ClubName)

因此尝试以下procedure

CREATE DEFINER=root@localhost PROCEDURE GetClubFixtures(clubName varchar(45))
BEGIN
SELECT FixtureDate, Tournament, HomeTeam, AwayTeam, KickOff
FROM  fixture
WHERE SeasonID in
(select SeasonID from season where seasonType=1) 
and 
(HomeTeam = ClubName 
or AwayTeam=ClubName)
ORDER BY FixtureDate;
于 2013-05-10T06:39:33.720 回答