Android高级-SQL语言

--创建表

第一种方式

create table t_hui(

  id integer,//

  name text,

  sex text,

//第一个参数为要创建的字段名,第二个参数为字段的类型

)

第二种方式

create table t_hui(

  id integer,//  primary key autoincrement //设置id为主键,并且自增加

  name text, unique //unique 代表该字段的值只能是唯一的,不能有重复

  sex text, not null default 20 // not null 代表不能为空,default 20 代表默认值为20

//第一个参数为要创建的字段名,第二个参数为字段的类型

)

--插入数据

INSERT INTO t_hui (name,age,sex) values ('是',18,'父')//向指定的地字段添加数据

INSERT INTO t_hui values ('是',18,'父')//向所有字段添加数据,有几个字段就添加几个值,不然会报错

--修改数据

UPDATE t_hui set name = '惠',age = 20 //语法 UPDATE t_hui set 字段1= '惠',字段2= 20

--删除数据

DELETE from t_hui //删除表内所有数据

DELETE from t_hui where name = '小龙女' //指定删除t_hui表里面name字段为小龙女的数据

--排序查询

select from t_hui order by age //查询t_hui表内age的数据,并且对他进行升序排序,desc是降序

--求和

select avg(age) from t_hui //求平均值t_hui表内age的数据

select max(age) from t_hui //求最大值t_hui表内age的数据

select age from t_hui where age in(1,3,4,5,67,7)//查询多个数值

--LIKE操作符

select from t_hui where name '%惠'//筛选以惠为结尾的数据

select from t_hui where name '%惠%'//筛选有惠的数据

select from t_hui where name '惠%'//筛选以惠为开头的数据

--分页查询

select from t_hui limit 0,8 //从0之后开始查询,查询数量为8个,

select * from t_hui p join t_tao s on s.id = p.id //联合查询

//join 是把两个表联合到一起,on是联合查询的id

原文地址:https://www.cnblogs.com/langfei8818/p/5885973.html