需求
一个开服表,包括 gameId 字段、服务器、开服时间等字段
要求对每个游戏最多显示两条开服消息,按时间倒序
SELECT * FROM `tbl_gamekf` `GameKf` LEFT OUTER JOIN `tbl_game` AS `Game`
ON `GameKf`.`gameId` = `Game`.`id`
WHERE 2 > (SELECT COUNT(*) FROM `tbl_gamekf` WHERE `gameId` = `GameKf`.`gameId` AND `time` > `GameKf`.`time`)
ORDER BY time DESC;
LEFT OUTER JOIN 可以忽略,重点是 WHERE 后的自连接查询