查询语句
2016-03-13 10:39
274 查看
1.普通查询
select * from Info #查询所有内容
select Code,Name from Info #查询某几列
2.条件查询
select * from Info where Nation = 'n001' #条件查询
select * from Info where Nation = 'n001' and Sex = true #条件之间并的关系
select * from Info where Sex = false or Nation = 'n002' #条件之间或者的关系
3.模糊查询 关键字 like %表示若干字符
select * from Chinastates where AreaName like '中%' #查询以“中”开头的
select * from Chinastates where AreaName like '%城%' #查询包含“城”的信息
select * from Chinastates where AreaName like '_城%' #查询“城”在第二个位置出现的数据
4.排序查询 关键字 order by desc 降序 asc升序
select * from Car order by Code desc #desc 降序 asc升序
select * from Car order by Brand
select * from Car order by Brand , Powers #按照两个列排序
5.统计查询(聚合函数) 关键字 count max min sum
select count(Code) from Car #查询总条数
select max(Price) from Car #查询最大值
select min(Price) from Car #查询最小值
select avg(Price) from Car #查询平均值
select sum(Price) from Car #查询总和
6.分组查询 关键字 group by
select Brand,count(*) from Car group by Brand #根据系列分组查看每组的数据条数
select * from Car group by Brand having count(*)>2 #查询分组之后数据条数大于2的
7.分页查询 关键字 limit
select * from Car limit 5,5 #跳过几条数据取几条数据 (N-1)*5
select * from Info #查询所有内容
select Code,Name from Info #查询某几列
2.条件查询
select * from Info where Nation = 'n001' #条件查询
select * from Info where Nation = 'n001' and Sex = true #条件之间并的关系
select * from Info where Sex = false or Nation = 'n002' #条件之间或者的关系
3.模糊查询 关键字 like %表示若干字符
select * from Chinastates where AreaName like '中%' #查询以“中”开头的
select * from Chinastates where AreaName like '%城%' #查询包含“城”的信息
select * from Chinastates where AreaName like '_城%' #查询“城”在第二个位置出现的数据
4.排序查询 关键字 order by desc 降序 asc升序
select * from Car order by Code desc #desc 降序 asc升序
select * from Car order by Brand
select * from Car order by Brand , Powers #按照两个列排序
5.统计查询(聚合函数) 关键字 count max min sum
select count(Code) from Car #查询总条数
select max(Price) from Car #查询最大值
select min(Price) from Car #查询最小值
select avg(Price) from Car #查询平均值
select sum(Price) from Car #查询总和
6.分组查询 关键字 group by
select Brand,count(*) from Car group by Brand #根据系列分组查看每组的数据条数
select * from Car group by Brand having count(*)>2 #查询分组之后数据条数大于2的
7.分页查询 关键字 limit
select * from Car limit 5,5 #跳过几条数据取几条数据 (N-1)*5
相关文章推荐
- POJ-2299- Ultra-QuickSort-树状数组离散化
- Ordered Fractions--最大公约数+pair
- SVN
- NSCopy与NSMutableCopy技术点
- 构造函数
- Eoeclient源代码分析---SlidingMenu的使用
- 学习进度条记录
- C#中sleep和wait的区别分析
- 爬虫训练营-基础之模拟请求
- 2016蓝桥杯算法训练——2的次幂表示
- 2016年第5本:必然
- attachEvent与addEventListener区别
- 转载:如何用数据驱动产品和运营
- Java运算符优先级
- UI整理-----part9--标签控制器(tabBarController)
- T-SQL 增删改查操作
- Ubuntu 15.10 程序“java”已包含在下列软件包中,安装jdk1.8.73
- Java编程规范
- 初次接触深度搜索DFS
- 为什么银行有取号机而超市结账的时候没有