Discuss / SQL / 1

如果有where语句时,order by 需要放在后面

ywjco_567

#2 Created at ... [Delete] [Delete and Lock User]

放在前面是语法错误。

SELECT id, name, gender, score
FROM students
ORDER BY score DESC
WHERE class_id = 1;
ERROR when execute SQL: SELECT id, name, gender, score
FROM students
ORDER BY score DESC
WHERE class_id = 1
SyntaxError: Parse error on line 3:
...ORDER BY score DESCWHERE class_id = 1
----------------------^
Expecting 'EOF', 'WITH', 'COMMA', 'RPAR', 'UNION', 'INTERSECT', 'EXCEPT', 'LIMIT', 'OFFSET', 'END', 'ELSE', 'GO', 'SEMICOLON', got 'WHERE'

WHERE是操作的条件,用于取得查询结果;

order by 是对操作返回的结果进行排序,所以需要放在后面。


  • 1

Reply