需求
同时查出各部门的工资以及公司的总工资
with a as ( select sum(sal) `total sal` from tb_emp)
select deptno,
sum(sal) over (distribute by deptno),
a.`total sal`
from tb_emp,a;
±-----±----±--------+
|deptno|c1 |total sal|
±-----±----±--------+
|NULL |NULL |29025 |
|10 |8750 |29025 |
|10 |8750 |29025 |
|10 |8750 |29025 |
|20 |10875|29025 |
|20 |10875|29025 |
|20 |10875|29025 |
|20 |10875|29025 |
|20 |10875|29025 |
|30 |9400 |29025 |
|30 |9400 |29025 |
|30 |9400 |29025 |
|30 |9400 |29025 |
|30 |9400 |29025 |
|30 |9400 |29025 |
±-----±----±--------+
另外,这个需求用join是实现不了的,因为join得有个关联条件,而在这里并没有关联条件,我们的需求就是每一行都加一个固定的字段值, 这种需求就要通过上面的方法完成.