zoukankan      html  css  js  c++  java
  • mysql(五)

    DQL:查询语句

      排序查询

        order by  排序字段1,排序字段2

        排序方式:

          ASC:升序,默认

          DESC:降序

        如果有多个排序字段,则前面条件一致时,才会判断第二条件

        select *from 表名  order by 字段名  DESC

      聚合函数:

        count:计算个数

        max:最大值

        min:最小值

        avg:平均值

        *注意:聚合函数的计算排除null值

        解决方案

          选择不包含null的列记性计算,一般用主键

          使用IFNULL 

          select count(ifnull(english,0)) from student

      分组查询:

        group by  字段名

        select  count(id)from   student  group by  sex  #找出学生男女分别个数

        select  count(id) from student where score > 70 group by  sex  having count(id)> 2

        *注意:where 在分组之前进行限定,如果不满足条件不参与分组,having在分组之后限定,如果不满足条件则不会被查询出来,where后不可以跟聚合函数,having可以进行聚合函数的判断

      分页查询:

        limit  起始位置,查询个数

        select * from student  limit 0,3

        *注意limit只适用于mysql

      完整查询:

        select  字段列表  from   表名列表  where  条件列表  group by  分组列表  having  条件列表  order  by  排序列表

            

      

  • 相关阅读:
    学习规划
    一位十年的老司机告诉你什么是编程思想
    React开发
    一个简单的ipfs音乐播放器的实现
    React错误总结(三)
    React错误总结解决方案(二)
    mongoid模糊查询
    Rails accepts_nested_attributes_for表单嵌套的利器
    route_path
    "constantize" and "with_indifferent_access" method
  • 原文地址:https://www.cnblogs.com/saber-xi/p/10624069.html
Copyright © 2011-2022 走看看