mysql

1. Aggregate functions (sum, count, avg, max, min), which act on multiple records.

1、select sum(population) from country

2、select region ,sum(population) ,sum(count) from country group by region having  sum(count)>1000

where filter records before aggregation

group by

Having filters group records after aggregation , and cannot use where to filter sum(count)>1000, because such a record does not exist in the country table

Query the number of employees in various positions in each department

3、select deptno,job,count(*) from emp group by deptno,job

4、select deptno,sum(sal) from emp where sal>1200 group by deptno having sum(sal)>10000 order by deptno


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324523709&siteId=291194637