在SQL中,可以使用ORDER BY子句對(duì)查詢結(jié)果進(jìn)行排序。ORDER BY子句通常在SELECT語(yǔ)句的末尾,可以按照一個(gè)或多個(gè)列進(jìn)行排序,也可以指定排序的順序(升序或降序)。
以下是一些示例:
SELECT column1, column2
FROM table_name
ORDER BY column1;
SELECT column1, column2
FROM table_name
ORDER BY column1, column2;
SELECT column1, column2
FROM table_name
ORDER BY column1 DESC;
SELECT column1, column2, column1 + column2 AS total
FROM table_name
ORDER BY total;
SELECT column1, column2
FROM table_name
ORDER BY column1 COLLATE NOCASE;
需要注意的是,ORDER BY子句必須在SELECT語(yǔ)句的最后,否則會(huì)導(dǎo)致語(yǔ)法錯(cuò)誤。