基本語法如下
sqlite> select * from tb_user; sqlite> select userid,username from tb_user;
格式化的查詢輸出
sqlite> .header on sqlite> .mode column sqlite> select * from tb_user;
設置輸出列的寬度
sqlite> .width 10, 20, 10 sqlite> select * from tb_user;
SQLite 的 ORDER BY 子句是用來基於一個或多個列按升序或降序順序排列數據。
基本語法:SELECT column-list FROM table_name [WHERE condition] [ORDER BY column1, column2, .. columnN] [ASC | DESC];
sqlite> select * from tb_user order by name asc; -- 結果按 name 升序排序: sqlite> select * from tb_user order by name desc; -- 結果按 name 降序排序: sqlite> select * from tb_user order by name,age asc; -- 結果按 name 和 age升序排序:
SQLite 的 Distinct 關鍵字
基本語法:SELECT DISTINCT column1, column2,.....columnN FROM table_name WHERE [condition]
sqlite> select distinct name from tb_user; sqlite> select distinct name,age from tb_user; sqlite> select distinct name,age from tb_user where name="liu";
