首页 > 数据库技术 > 详细

MySql各种查询

时间:2016-05-27 07:05:04      阅读:285      评论:0      收藏:0      [点我收藏+]

1.简单查询

  select * from info;

  select Code as ‘代号‘,name as ‘姓名‘ from info;

2.条件查询

  select * from car where code = ‘c002‘;

  select * from car where brand =‘b001‘ and power = 130; #或用or

3.模糊查询

  select * from car where name like ‘%奥迪%‘;  %代表任意多个字符包括0个 _代表一个字符

4.排序查询

  select * from car order by brand, powers desc; asc升序默认可以不写

5。范围查询

  select * from car where price between 40 and 60;

6.离散查询

  select * from car where code in(‘coo1‘,‘c003‘,‘c005‘,‘c007‘);

  select * from car where code not in(‘coo1‘,‘c003‘,‘c005‘,‘c007‘);

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

  select count(code) from car;  查询数据条数也可以count(*)这么写,性能低

  select sum(price) from car;  求和

  select max(code) from car;  最大  

  select min(brand) from car;  最小

  select avg(price) from car;  平均

8.分页查询

  select * from Car limit (n-1)*5,5  #第n页,每页显示五条数据

9.去重查询

  select distinct Brand from Car

10.分组查询 

  select brand,count(*),Brand from Car group by Brand   #把brand列的相同值组合起来,并这一条数据对该列或或其他列进行操作例如求平均值
  select Brand from Car group by Brand having count(*)>3 #分组之后根据条件查询使用having 不使用where

 

MySql各种查询

原文:http://www.cnblogs.com/yongjiapei/p/5533301.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!