Sqlite—查询语句(Select)

基本语法如下

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";

  

原文地址:https://www.cnblogs.com/liuhaidon/p/11962313.html