有下games
表
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`content` text COLLATE utf8_unicode_ci,
`team1ID` int(7) unsigned DEFAULT NULL,
`team2ID` int(7) unsigned DEFAULT NULL,
`championshipID` int(10) unsigned DEFAULT NULL,
`date` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `FK_Event_team1ID_Team_id` FOREIGN KEY (`team1ID`) REFERENCES `Team` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `FK_Event_team2ID_Team_id` FOREIGN KEY (`team2ID`) REFERENCES `Team` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
我需要的是从team
按游戏计数(剩余游戏计数)排序的表中获取团队名称列表。有关位于games
表中的游戏的所有详细信息
我将描述条件:
- 和
games.championshipID=1
- 列表必须按降序排列(从最大游戏数到最小)
- 游戏计数必须
games
通过搜索在表格中计算games.team1ID, games.team2ID
- 和
games.date
> 当前时间戳
结果一定是这样的
team name | games left
teamWithId5 | 68 (row count from games table)
teamWithId250| 50
teamWithId250 | 4
无法弄清楚 sql 查询必须是什么样子。有什么建议么?
提前谢谢