数据库查询或删除语句
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
SQLite中的数据类型:
1、整数类型:int integer
2、小数类型:real float double
3、文本类型:text varchar char
Varchar(10):可变长度的文本类型
Char(10):定长的文本类型
例题: Create table student
(
Id integer,
Name varchar(50),
Age integer
);
一、查询语句
select 列名1,列名2... from 表名 where 条件
运算符:
1》、比较运算符 :> >= < <= != <> =
2》、 and or not
1、显示所有的图书
select * from book;
2、显示所有的图书,每本书只显示编号和书名
select id,name from book;
3、显示书名为Java的图书
select * from book where name='Java';
3、显示价格在50元以上的图书信息
select * from book where price>50;
4、显示价格在30到60之间的图书信息
select * from book where price>=30 and price<=60;
select * from book where price between 30 and 60;
5、显示价格在50元以下,或者价格在80元以上的图书信息
select * from book where price<50 or price>=80;
6、显示作者为zhangsan的图书信息
select * from book where author='zhangsan';
7、显示作者不是zhangsan的图书信息
select * from book where author!='zhangsan';
select * from book where author<>'zhangsan';
8、显示所有不知道作者的图书信息
select * from book where author is null;
9、显示所有知道作者的图书信息
select * from book where author is not null;
10、显示价格没有录入的图书信息
select * from book where price is null;
11、显示价格为30、40、60、80的图书信息
select * from book where price=30 or price=40 or price=60 or price=80;
select * from book where price in(30,40,60,80);
12、显示价格不为30、40、60、80的图书信息
select * from book where price not in(30,40,60,80);
13、显示所有图书信息,并按价格升序排序
select * from book order by price [asc];
14、显示所有图书信息,并按价格降序排序
select * from book order by price desc;
15、显示所有作者为zhangsan的图书信息,并按价格升序排序
select * from book where author='zhangsan' order by price ;
16、显示所有图书信息,并按价格升序排序,如果价格一样,则按照编号降序排序
select * from book order by price ,id desc;
17、显示所有图书信息,按照作者升序排序
select * from book order by author;
18、显示所有姓小的作者写的图书(模糊查询) _ 一个任意字符 % :0到n个任意字符列名 like '小%'
select * from book where author like '小%';
select * from book where author like 'zhang%';
二、删除或修改
1、删除id为11的学生
delete from student where id=11 ;
2、删除id为1的学生
delete from student where id=1;
drop
table 表名; 删除指定的表
3、将姓名为cc的学生的年龄修改为19岁
update student set age=19 where name='cc';
4、将id为10的学生姓名修改为zz,年龄为30
update student set name='zz',age=30 where id=10;
5、查询共有多少个学生
count(列名):统计指定的列的非空值有多少个
select count(age) from student;
select count(*) from student;
6、查询所有学生中最大的年龄
select max(age) from student;
7、查询所有学生中年龄最大的学生的信息
(1)找到最大年龄
select max(age) from student;
(2)根据最大年龄查找学生信息
select * from student where age=(select max(age) from student);
8、查询所有学生中最小的年龄 min
select min(age) from student;
9、查询所有学生中年龄最小的学生的信息 min
select * from student where age=(select min(age) from student);
10、求所有学生的平均年龄 avg(列名) sum(列名)
select avg(age) from student;
11、查询所有年龄在平均年龄以上的学生信息
selrct * from student where age=(select avg(age) from student);