码迷,mamicode.com
首页 > 数据库 > 详细

CRUD操作数据库

时间:2017-12-31 14:44:39      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:tin   列排序   .com   count   asc   info   范围   order   字符   

3.给列指定名称

select code as ‘代号‘,name as ‘姓名‘ from info

技术分享图片

4.条件查询

select * from info where code=‘p001‘

select * from info where code=‘p001‘ or nation=‘n001‘ 或关系

select * from info where  code=‘p001‘ or nation=‘n001‘ 并且关系

5.模糊查询(经常用到)

select * from car where name like ‘%奥迪%‘   前面后面有n个字符 

select * from car where name like ‘_奥迪%‘     前面出现一个字符

6.排序查询

默认为主键排序

select * from car  order by price    以价格进行排序,默认按升序排序

select * from car order by price desc      按降序排列

select * from car order by price asc     按升序排列

select * from car order by price asc,oil desc 按两列排序

7.去重查询

select  brand from car 查询brand列

select distinct brand from car 去重查询

8.分页查询(取几条数据)

select * from car limit 5,5  跳过5条,取5条  (当前页-1)*5

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

  数据条数

 select count(*) from car  有多少数据

 select count(code) from car  只看主键列,可以提高查询效率

取最大值

select max(price) from car  取price列的最大值

最小值 

select min(price) from car 取price列的最小值

取平均值

select avg(price) from car 取price的平均值

10.分组查询

根据某一列分组,统计某一组的数量

select  brand, count(*) from car group by brand

技术分享图片

select brand from car group by brand having count(*)>=3

11.范围查询

select * from car where price>=40 and price<=60

select * from car where price between 40 and 60

12.离散查询

select * from car where price in (10,20,30)

select * from car where price not in(10,20,30)

 

CRUD操作数据库

标签:tin   列排序   .com   count   asc   info   范围   order   字符   

原文地址:https://www.cnblogs.com/niushuangmeng/p/8157623.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!