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  排序列表

            

      

  • 相关阅读:
    关于JavaScipt对象的基本知识
    《最终幻想6》敌人全部魔法一览
    敬爱的GitHub” —— 致GitHub的一封地下信   英文原文:"Dear GitHub…" An Open Letter to GitHub
    分享十个JavaScript在线调试工具
    分享十二个有用的jQuery代码
    进度条
    标准Lookup中使用Group By 过滤数据
    常用的X++
    输出Warning后,判断是断续
    ax没有distinct ,只能projId进行group by
  • 原文地址:https://www.cnblogs.com/saber-xi/p/10624069.html
Copyright © 2011-2022 走看看