# 对查询的结果进行排序 查询结果返回的顺序可能是任意顺序,如果想要根据特定字段排序返回结果集,需要在 SELECT 语句最后面增加 ORDER BY 子句指定返回顺序。SQL 语句格式如下: ~~~ SELECT select_list FROM table_list WHERE query_condition ORDER BY column_list ~~~ 如查看 2 号仓库第 5 区的客户,按姓名排序,SQL 语句如下: ~~~ SELECT c_id, c_last,c_first,c_middle, c_w_id, c_d_id, c_credit, c_since FROM cust WHERE c_w_id=2 AND c_d_id=5 ORDER BY c_last, c_first; ~~~ 执行结果如下: ~~~ +------+----------------+------------------+----------+--------+--------+----------+------------+ | c_id | c_last | c_first | c_middle | c_w_id | c_d_id | c_credit | c_since | +------+----------------+------------------+----------+--------+--------+----------+------------+ | 202 | ABLEBAROUGHT | omHvv5eG | OE | 2 | 5 | GC | 2020-02-15 | | 272 | ABLECALLYOUGHT | x0ikkFsuG | OE | 2 | 5 | GC | 2020-02-15 | | 2106 | ABLECALLYPRI | Hksk96bvVRAZ | OE | 2 | 5 | GC | 2020-02-15 | | 2813 | ABLEPRESEING | GxtYNqeRZFIaWmN | OE | 2 | 5 | GC | 2020-02-15 | | 2360 | ANTIATIONATION | BcIWNvikBc | OE | 2 | 5 | GC | 2020-02-15 | | 2500 | ANTIEINGCALLY | WXBmhcRTWe | OE | 2 | 5 | GC | 2020-02-15 | | 658 | ANTIESECALLY | ONPLFp6Htl | OE | 2 | 5 | BC | 2020-02-15 | | 1085 | ANTIOUGHTABLE | SstdwQNJJ | OE | 2 | 5 | GC | 2020-02-15 | | 2247 | ANTIPRIOUGHT | R1VEFjdPlOioo | OE | 2 | 5 | GC | 2020-02-15 | | 2100 | ATIONABLEESE | PzFg81YvfBC | OE | 2 | 5 | BC | 2020-02-15 | | 2196 | ATIONATIONBAR | ReFiFtMxfo1qG5 | OE | 2 | 5 | GC | 2020-02-15 | | 871 | ATIONCALLYBAR | W7ZNcPqp5sBWNi | OE | 2 | 5 | GC | 2020-02-15 | | 2999 | ATIONCALLYPRI | eQbIWEimKcM80xNB | OE | 2 | 5 | GC | 2020-02-15 | | 849 | ATIONPRESATION | Z6V2PdM8B0b9hQ8d | OE | 2 | 5 | GC | 2020-02-15 | | 8 | BARBARCALLY | jXrw6CCdzcamEi | OE | 2 | 5 | GC | 2020-02-15 | | 4 | BARBARPRI | KKvDumYX9AwHuxX | OE | 2 | 5 | GC | 2020-02-15 | | 1983 | BAROUGHTANTI | XeYW3WKpfBITC1aB | OE | 2 | 5 | GC | 2020-02-15 | | 1590 | BAROUGHTCALLY | Y886PI3rFsHCSMbF | OE | 2 | 5 | GC | 2020-02-15 | | 1529 | BAROUGHTPRI | pyP6QQj7FB | OE | 2 | 5 | GC | 2020-02-15 | | 34 | BARPRIPRI | gXmuxvj2R | OE | 2 | 5 | GC | 2020-02-15 | | 1785 | CALLYABLEESE | LsWK1Zs1pm | OE | 2 | 5 | GC | 2020-02-15 | | 2765 | CALLYABLEOUGHT | b0maEo4Nm2JgW2j | OE | 2 | 5 | GC | 2020-02-15 | | 2102 | CALLYABLEOUGHT | wPS9EgAgztLRvSuZ | OE | 2 | 5 | GC | 2020-02-15 | | 798 | CALLYEINGCALLY | Z9T8FivHqeaO | OE | 2 | 5 | GC | 2020-02-15 | | 2793 | CALLYEINGOUGHT | eVQqIPDaGOb7N3EN | OE | 2 | 5 | GC | 2020-02-15 | | 1370 | CALLYESEEING | J8Cakezt | OE | 2 | 5 | GC | 2020-02-15 | | 2660 | CALLYPRESPRES | FgxeQplwu | OE | 2 | 5 | GC | 2020-02-15 | | 2401 | CALLYPRIANTI | fJjIGGGH7Fdn1Kp | OE | 2 | 5 | BC | 2020-02-15 | | 926 | EINGABLEESE | NZLtbu8Jb7Qi | OE | 2 | 5 | GC | 2020-02-15 | | 2970 | EINGABLEOUGHT | PLnJDvKTwR0ireM | OE | 2 | 5 | GC | 2020-02-15 | | 2137 | EINGANTIEING | bDPeSSyD7 | OE | 2 | 5 | GC | 2020-02-15 | | 1334 | EINGBAREING | ep86qqrvFlD | OE | 2 | 5 | GC | 2020-02-15 | | 993 | EINGEINGABLE | mxu2u3eo | OE | 2 | 5 | GC | 2020-02-15 | | 956 | EINGESEESE | q02t2c9oR7 | OE | 2 | 5 | GC | 2020-02-15 | | 916 | EINGOUGHTESE | ungAvrh8dWoGlQlP | OE | 2 | 5 | GC | 2020-02-15 | | 569 | ESEANTIATION | xIZPuIwBJXxVIER | OE | 2 | 5 | GC | 2020-02-15 | | 1433 | ESEBARESE | jpTpJk5diH | OE | 2 | 5 | GC | 2020-02-15 | | 2405 | ESEBARESE | ZXKb7eR96iGg | OE | 2 | 5 | GC | 2020-02-15 | | 2101 | ESEPRESATION | DQUk9dys | OE | 2 | 5 | GC | 2020-02-15 | | 2348 | OUGHTCALLYANTI | w0rDw8txdIPfeElQ | OE | 2 | 5 | GC | 2020-02-15 | | 1093 | OUGHTCALLYESE | GBx3akVCEuTPLa | OE | 2 | 5 | BC | 2020-02-15 | | 193 | OUGHTEINGABLE | ImIEJkCzrYtEpaV4 | OE | 2 | 5 | GC | 2020-02-15 | | 1318 | PRESATIONEING | uT4TGkIdWf | OE | 2 | 5 | GC | 2020-02-15 | | 1813 | PRESATIONESE | SsF8v3NE | OE | 2 | 5 | GC | 2020-02-15 | | 1991 | PRESESEANTI | GhytcH1EQhY | OE | 2 | 5 | GC | 2020-02-15 | | 414 | PRESOUGHTPRI | vTsmW2XU | OE | 2 | 5 | GC | 2020-02-15 | | 1979 | PRESPRESANTI | GGsWcgaTLXjtXAN | OE | 2 | 5 | GC | 2020-02-15 | | 1184 | PRESPRESEING | hs5Bd47ZlZghuD8 | OE | 2 | 5 | GC | 2020-02-15 | | 440 | PRESPRIEING | O4Vjdc3hmk4DT | OE | 2 | 5 | GC | 2020-02-15 | | 1766 | PRIABLEEING | hqPJlwGx6Qt0FXy | OE | 2 | 5 | GC | 2020-02-15 | | 372 | PRICALLYOUGHT | HpbvP0rDZM3 | OE | 2 | 5 | GC | 2020-02-15 | | 356 | PRIESEESE | lZlbGnZhIlYH6nP | OE | 2 | 5 | GC | 2020-02-15 | +------+----------------+------------------+----------+--------+--------+----------+------------+ 52 rows in set (0.01 sec) ~~~