我现在对你的喜欢,比昨天多一点点,比明天少一点点;
分组查询主要使用的是group by语句。
技巧:可以吧select后面列表中的字段添加到group by语句的子句中即可。
select deptno, sum(sal)
from scott.emp
group by deptno;
其实很简单,就是以deptno作为一个参照,根据参照物定义出条件对象。
如果在分组以后,还需要进行条件过滤,可以使用having关键字,追加条件
select deptno, sum(sal)
from scott.emp
group by deptno
having sum(sal) > 1000;
常见关键字使用顺序