MySql基础查询-分组函数

#分组函数
#1. 查询公司员工工资的最大值,最小值,平均值,总和

SELECT SUM(salary),MAX(salary),MIN(salary),AVG(salary),COUNT(salary) FROM employees
#工资去重
SELECT
    sum( DISTINCT salary ),
    sum( salary ) 
FROM
    employees

#查询有几种工资
SELECT count(DISTINCT salary) FROM employees
#统计工资的个数
SELECT count(salary) FROM employees
#统计总行数即总记录条数

SELECT count(*) FROM employees
SELECT count(1) FROM employees

#2. 查询员工表中的最大入职时间和最小入职时间的相差天数 (DIFFRENCE)

SELECT
    datediff(
        max( hiredate ),
    min( hiredate )) AS ‘相差天数‘ 
FROM
    employees

#3. 查询部门编号为90的员工个数
SELECT count(*) FROM employees WHERE department_id=90

MySql基础查询-分组函数

上一篇:MYSQL 与 PostgreSQL 在命令行中执行SQL语句


下一篇:mysql系统日志 (binlog, redolog, undolog, errorlog, generallog, relaylog, slowquerylog)