您的位置:首页 > 数据库

[SQLite]SQL语法

2015-08-17 22:47 429 查看

SQLite常用SQL语句

创建表格

sql="CREATE TABLE IF NOT EXISTS MusicList (id integer primary key AutoIncrement,name varchar(20),path varchar(20))";

查询表格

查看表结构

desc <table>;


查看所有数据

select * from <table>;


查看指定的列数据

select , from <table>;


查看非重复数据

select distinct , from <table>;


复制数据

insert into users(_id,username,password) select * from users;


首字母为S的数据

select username from users where username like 'S%' ;


第三个字母为S的数据

select username from users where username like '__S%' ;


查询001,220,230的数据

select * from users where _id in(001,220,230);


顺序查询

select * from users where _id in(001,220,230);


反顺序查询

select * from user order by _id desc;


分页功能

获取数据行总数

select count(word) as number from <table>;


分页查询

select , from <table> order by word limit 100 offset 200;


SQLite内建函数表

算术函数

abs(X)
返回给定数字表达式的绝对值。

max(X,Y[,...])
返回表达式的最大值。

min(X,Y[,...])
返回表达式的最小值。

random(*)
返回随机数。

round(X[,Y])
返回数字表达式并四舍五入为指定的长度或精度。

字符处理函数

length(X)
返回给定字符串表达式的字符个数。

lower(X)
将大写字符数据转换为小写字符数据后返回字符表达式。

upper(X)
返回将小写字符数据转换为大写的字符表达式。

substr(X,Y,Z)
返回表达式的一部分。

randstr()


quote(A)


like(A,B)
确定给定的字符串是否与指定的模式匹配。

glob(A,B)


条件判断函数

coalesce(X,Y[,...])


ifnull(X,Y)


nullif(X,Y)


集合函数

avg(X)
返回组中值的平均值。

count(X)
返回组中项目的数量。

max(X)
返回组中值的最大值。

min(X)
返回组中值的最小值。

sum(X)
返回表达式中所有值的和。

其他函数

typeof(X)
返回数据的类型。

last_insert_rowid()
返回最后插入的数据的ID。

sqlite_version(*)
返回SQLite的版本。

change_count()
返回受上一语句影响的行数。

last_statement_change_count()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: