After the screening group mysql query

Syntax:
SELECT grouping function, a column (required appear behind the group by)
from table
WHERE ..
group by grouping list
order by ...

Case #: query the various departments of the average wage

SELECT AVG(salary),department_id
FROM employees
GROUP BY
    department_id
ORDER BY
    department_id DESC;

Case #: Query maximum wage for each type of work

SELECT
    MAX(salary),job_id
FROM
    employees
GROUP BY
    job_id;

Case #: The number of location queries for each department

SELECT
    COUNT(location_id),department_name
FROM
    departments
GROUP BY
    department_name;

Case #: Query average wage mailbox contains a character for each department

SELECT
    AVG(salary),department_id
FROM
    employees
WHERE
    email LIKE('%a%')
GROUP BY
    department_id;

Case #: Query every leader has the highest salary of his employee bonuses

SELECT
    MAX(salary),manager_id
FROM 
    employees
WHERE
    commission_pct IS NOT NULL
GROUP BY 
    manager_id;

Guess you like

Origin blog.51cto.com/14437184/2436585