sqlite
Database; use; embedded relational database
order
英[??:d?(r )] US [??:rd?(r)]
n. Order; command; sequence; rule, system
vt. Order; order; sort
vi. Order
by
UK[ba?] US[ba?]
prep.beside...;expression;due to;after
adv. pass; means to reserve or save; use; to visit briefly
SQLite Order By function syntax
Function:SQLite's ORDER BY clause is used to arrange data in ascending or descending order based on one or more columns.
Grammar: The basic syntax of the ORDER BY clause is as follows:
SELECT column-list
FROM table_name
[WHERE condition]
[ORDER BY column1, column2, .. columnN] [ASC | DESC];
You can use multiple columns in the ORDER BY clause. Make sure the sort column you are using is in the column list.
SQLite Order By function example
COMPANY 表有以下記錄: ID NAME AGE ADDRESS SALARY ---------- ---------- ---------- ---------- ---------- 1 Paul 32 California 20000.0 2 Allen 25 Texas 15000.0 3 Teddy 23 Norway 20000.0 4 Mark 25 Rich-Mond 65000.0 5 David 27 Texas 85000.0 6 Kim 22 South-Hall 45000.0 7 James 24 Houston 10000.0 下面是一個(gè)實(shí)例,它會(huì)將結(jié)果按 SALARY 升序排序: sqlite> SELECT * FROM COMPANY ORDER BY SALARY ASC; 這將產(chǎn)生以下結(jié)果: ID NAME AGE ADDRESS SALARY ---------- ---------- ---------- ---------- ---------- 7 James 24 Houston 10000.0 2 Allen 25 Texas 15000.0 1 Paul 32 California 20000.0 3 Teddy 23 Norway 20000.0 6 Kim 22 South-Hall 45000.0 4 Mark 25 Rich-Mond 65000.0 5 David 27 Texas 85000.0 下面是一個(gè)實(shí)例,它會(huì)將結(jié)果按 NAME 和 SALARY 升序排序: sqlite> SELECT * FROM COMPANY ORDER BY NAME, SALARY ASC; 這將產(chǎn)生以下結(jié)果: ID NAME AGE ADDRESS SALARY ---------- ---------- ---------- ---------- ---------- 2 Allen 25 Texas 15000.0 5 David 27 Texas 85000.0 7 James 24 Houston 10000.0 6 Kim 22 South-Hall 45000.0 4 Mark 25 Rich-Mond 65000.0 1 Paul 32 California 20000.0 3 Teddy 23 Norway 20000.0 下面是一個(gè)實(shí)例,它會(huì)將結(jié)果按 NAME 降序排序: sqlite> SELECT * FROM COMPANY ORDER BY NAME DESC; 這將產(chǎn)生以下結(jié)果: ID NAME AGE ADDRESS SALARY ---------- ---------- ---------- ---------- ---------- 3 Teddy 23 Norway 20000.0 1 Paul 32 California 20000.0 4 Mark 25 Rich-Mond 65000.0 6 Kim 22 South-Hall 45000.0 7 James 24 Houston 10000.0 5 David 27 Texas 85000.0 2 Allen 25 Texas 15000.0