0

我有以下查询,它查询涉及球队的最近 20 场比赛的运动结果表,返回每场比赛的失球数。

SELECT *, `against` AS `goalsF` , `for` AS `goalsA`
FROM `matches` , `teams` , `outcomes`
WHERE (
`home_team_id`=7 AND `matches`.away_team_id = `teams`.team_id

OR 
`away_team_id`=7 AND `matches`.home_team_id = `teams`.team_id
)
AND `matches`.score_id = `outcomes`.outcome_id
ORDER BY `against', `date` DESC
LIMIT 0 , 20

我想按失球对结果进行排序,然后在每组失球中按日期对结果进行排序,例如。

前 4 个结果,其中失球数按日期顺序为 1,然后接下来的 3 个结果可能是按日期顺序失球数=2

我已经尝试过ORDER by date,against-这给了我尝试过的严格日期顺序ORDER by against,date-这给了我过去 20 次之后的匹配

有可能做我想做的事吗?

4

2 回答 2

0

谢谢大家,我发现这有效。此解决方案由另一个用户发布,但随后被删除,不知道为什么?

SELECT * FROM (
    SELECT *, `against` AS `goalsF` , `for` AS `goalsA`
    FROM `matches` , `teams` , `outcomes`
    WHERE (
        `home_team_id`=7 AND `matches`.away_team_id = `teams`.team_id
        OR 
        `away_team_id`=7 AND `matches`.home_team_id = `teams`.team_id
    )
    AND `matches`.score_id = `outcomes`.outcome_id
    ORDER by `goalsF`
    LIMIT 0 , 20
) res
ORDER BY `date` DESC
于 2013-07-03T09:57:19.237 回答
-1

如果您想按日期进行限制,请将您要查找的日期范围添加到 WHERE 子句中,然后按失球数排序。

于 2013-07-02T16:21:10.430 回答