简单查询(1.普通查询2.条件查询3.模糊查询4.排序查询5.统计查询(聚合函数)6.分组查询7.分页查询)...

1.普通查询

select * from Info #查询Info表中所有内容

select Code,Name from Info #查询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.模糊查询(搜索关键字、名称)

select * from ChinaStates where AreaName like '中%' #查询一中开头的

select * from ChinaStates where AreaName like '%城%' #查询包含城的信息

select * from ChinaStates where AreaName like '_城%' #查询城在第二个位置出现的数据

4.排序查询

select * from Car order by Code #desc降序 asc 升序

select * from Car order by Brand

select * from Car order by Brand,Powers #按照两个列排序

关键字 order desc降序 asc 升序

5.统计查询(聚合函数)

select count(Code) from Car #查询总条数 *\Code\1

select max(Price) from Car #查询最大值

select min(Price) from Car #查询最小值

select avg(Price) from Car #查询平均值

select sum(Price) from Car #查询总和

6.分组查询

select Brand,count(*) from Car group by Brand #根据系列分组查看没组的数据条数 Brand 前面可以加任意一组的名并查询

select * from Car group by Brand having count(*) >2 #group 后不可用where只能用 having,查询分组之后数据条数大于2的

7.分页查询

select * from Car limit 0,5 #跳过几条数据取几条数据(N-1)*5

 

转载于:https://www.cnblogs.com/Yue0327/p/5275480.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值