我试图实现这个问题的答案。答案确实有效,但我发现我错过了为表中的列实现子句ORDER BY
(我已经检查过该列是否确实存在)。但我无法让它工作。这就是我的问题归结为。这有效:order
qrgame_place
sql = '''SELECT P.id, (TP.id IS NOT NULL) AS done
FROM qrgame_place P
LEFT OUTER JOIN qrgame_team_places TP
ON P.id = TP.place_id AND TP.team_id = %s
WHERE P.game_id = %s
'''
但这不会:
sql = '''SELECT P.id, (TP.id IS NOT NULL) AS done
FROM qrgame_place P
LEFT OUTER JOIN qrgame_team_places TP
ON P.id = TP.place_id AND TP.team_id = %s
WHERE P.game_id = %s
ORDER BY P.order ASC
'''
我试图改变的地方,ORDER BY
但它不会帮助。
Django 在模板中给我的错误是:
Exception Type: DatabaseError
Exception Value: near "order": syntax error
我对 SQL 语言有什么不了解的地方?