MySQL-DQL-aggregate function

Table of contents

aggregate function

Precautions


  • aggregate function

    • Introduction: Take the data in the table as a whole and perform longitudinal calculations
    • Syntax: select aggregate function (field list) from table name
    • SUM summation
    • COUNT statistics
      • specific code
      • -- 1.统计该企业员工数量--count
        -- count(字段)
        select count(id)
        from tb_emp;
        -- count(常量)
        select count('A')
        from tb_emp;
    • AVG average
      • specific code
      • -- 4.统计该企业ID的平均值--avg
        select avg(id)
        from tb_emp;
    • MAX maximum value
      • specific code
      • -- 3.统计该企业最迟入职员工--max
        select max(entrydate)
        from tb_emp;
    • MIN minimum value
      • specific code
      • -- 2.统计该企业最早入职员工--min
        select min(entrydate)
        from tb_emp;
  • Precautions

    • Null values ​​do not participate in the operation of all aggregate functions
    • Statistics can be used: count (*), count (field), count (constant), it is recommended to use count (*)

Guess you like

Origin blog.csdn.net/weixin_64939936/article/details/131774849