我有以下查询,查询参与球队的最后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个可能是以日期顺序<= p>承认= 2的结果
我试过ORDER by date,against
- 这给了我一个严格的日期顺序
我试过ORDER by against,date
- 这给了我超过过去20的比赛
有可能做我想做的事吗?
答案 0 :(得分: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
答案 1 :(得分:-1)
如果您想按日期限制,请将您要查找的日期范围添加到WHERE子句中,然后按承诺的目标数量排序。