查询
1.简单查询
select * from info(表名) --查所有数据
select code(列名),name(列名) from 表名 --查指定列的数据
select code(列名) as ‘代号’,name(列名) as ‘姓名’ from info (改变列名) --给列指定别名
2.条件查询
select * from info(表名) where code(条件)=‘p001’
select * from info(表名) where sex(条件)=‘true’,and nation=‘n001’ --多条件并的关系
select * from info(表名) where sex(条件)=‘true’,or nation=‘n001’ --多条件或的关系
3.范围查询
select * from 表名 where 范围
select * from car where price>40 and price<50
select * from car where price between 40 and 50
4.离散查询
select * from car(表名) where code(列名) in(‘c001’,‘c005’,‘c010’,‘c015’)
select * from car where code not in(‘c001’,‘c005’,‘c010’,‘c015’)
5.模糊查询
select * from car(表名) where name(列名) like ‘%宝马(关键字)%’ --查包含宝马的
select * from car where name like ‘宝马%’ --查以宝马开头的
select * from car where name like ‘%宝马 --查以宝马结尾的’
select * from car where name like ‘宝马’ --查等与宝马的
select * from car where name like‘—E%’ --查第三个字符是E的
%代表是任意多个字符
-代表是一个字符
6.排序查询
select *from car(表名) order by price(列名) asc --以价格升序排列
select *from car(表名) order by price desc –以价格降序排列
select *from car order by 0il desc, price asc --以两个字段排序,前面的是主条件后面的是次要条件
7.分页查询
select top 5 * from car
select top 5 * from car where code not in (select top 5 code from car)
当前页:page = 2 row= 10
select top row *from car where code not in (select top (page-1) * row code from car)
8.去重查询
select distinct brand from car
9.分组查询
select Brand from car group by Brand having count(*)>2
10.聚合函数(统计查询)
select count(*)查询完以后到底有多少数据 from car –查询所有数据条数
select count(code) from car --查询所有数据条数
select sum(price(列名)) from car(表名) 求和
select sum(price) from car 求和
select sum(price) from car 求和
select sum(price) from car 求和