我需要从数据库 team_1 和 team_2(足球比赛赛程)中选择并按比赛分组
$query = mysql_query("SELECT * FROM fixtures
GROUP BY team_1
ORDER BY match_date
LIMIT 0,10") or die(mysql_error());
工作正常,但是,足球赛程将通过用户输入,因此,有人可以输入例如
英格兰诉威尔士 有人可以进入 威尔士诉英格兰
它们显然是同一场比赛,如果 team_1(england) v team_2(wales) 与 team_1(wales) v team_2(england) 相同,我如何将比赛分组在一起
最佳答案
SELECT field1, field2, match_date, ......
,GREATEST(team_1,team_2) as team1
,LEAST(team_1,team_2) as team2
,field6, field7
FROM fixtures
GROUP BY team1
ORDER BY match_date
LIMIT 10 OFFSET 0;
关于php - Msql Select and group from db where team_1 和 team_2 相同但在条目中相反,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7470199/