首页 > 其他 > 详细

DQL查询语句的其他方法查询

时间:2019-11-19 14:41:12      阅读:137      评论:0      收藏:0      [点我收藏+]

1.查询语句

  order by 子句:

    order by 排序字段1 排序方式1,排序方式2 排序方式2 ...

  排序方式:

      asc:升序(默认)

       desc:降序

  注意:

    如果有多个排序条件时,则当前边的条件值一样时,才会判断第二个条件 如:select * from student order by math desc, english asc(按照数学成绩降序排列,如果数学成绩一样,则按照英语成绩升序排列)

2.聚合函数:将一列数据作为一个整体,进行纵向计算(比如计算数学吃绩这一列的平均分)

  Ⅰ.count:计算个数  

    count 排序的列

    根据某个列的属性来查询个数:

    select count(math) from student; 

       ②如果想要查询只要有一个数据不为空的就包含查询的个数,则:

       select count(*) from student; 

  Ⅱ.max:计算最大值

    select count(max) from student; 

  Ⅲ.min:计算最小值

    select count(min) from student;   

  Ⅳ.sum:求和

    select count(sum) from student; 

  Ⅴ.avg:计算平均值

    select count(avg) from student; 

  注意:所有的聚合函数都会排除空的数据,比如,根据英语成绩计算数量,如果有8个数据,其中一个的英语数据为null,则查询到的count为7 如:select count(english) from student;

      如果说非要根据英语成绩查询所有的数量且为8个,则使用ifnull 如:select count(ifnull(english,0)) from student;

3.分组查询

  group by子句:

    group by 分组的字段

      根据性别分组查询性别的数学成绩平均分,人数   如:select sex, avg(math), count(id) from student group by sex;

    注意:

    分组查询所查询的要么是分组的字段,要么是聚合函数的字段,否则分组查询就没有任何意义

4.分页查询

 

 

 

 

 

 

DQL查询语句的其他方法查询

原文:https://www.cnblogs.com/KeepCalmAndNeverSayNever/p/11889253.html

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