关于 "group function is not allowed here"
About "group function is not allowed here"
我有一个 table,其中包含工作、薪水和日期列。我在 PL/SQL 中编写以下查询,但出现错误
group function is not allowed here
delete employees where date = '06-05-2020 'and avg (salary)> 5500;
我该如何解决这个问题?
您的查询毫无意义(至少对我而言)。 平均工资代表什么? 谁的平均工资?
这是一个基于 Scott 的 EMP
table 的示例;我要删除1981年12月3日入职的员工平均工资高于2000的部门
示例数据:
SQL> select deptno, ename, sal, hiredate from emp order by deptno, ename;
DEPTNO ENAME SAL HIREDATE
---------- ---------- ---------- ----------
20 ADAMS 1100 12.01.1983
20 FORD 3000 03.12.1981 --> this
20 JONES 2975 02.04.1981
20 SCOTT 3000 09.12.1982
20 SMITH 800 17.12.1980
30 ALLEN 1600 20.02.1981
30 BLAKE 2850 01.05.1981
30 JAMES 950 03.12.1981 --> this
30 MARTIN 1250 28.09.1981
30 TURNER 1500 08.09.1981
30 WARD 1250 22.02.1981
11 rows selected.
每个部门的平均工资:
SQL> select deptno, avg(sal) avg_salary
2 from emp
3 group by deptno
4 order by avg_salary desc;
DEPTNO AVG_SALARY
---------- ----------
20 2175 --> higher than 2000
30 1566,66667
所以:我正在寻找在 20 部门工作的员工(因为只有那个部门的平均工资高于 2000)并且在 03.12.1981 被录用(James和福特,但只有 Ford 在 20 部门工作):
SQL> delete from emp
2 where hiredate = date '1981-12-03'
3 and deptno in (select deptno
4 from emp
5 group by deptno
6 having avg(sal) > 2000
7 );
1 row deleted.
福特还在吗?
SQL> select * From emp where ename = 'FORD';
no rows selected
SQL>
没有,删了。
现在,轮到你了。
我有一个 table,其中包含工作、薪水和日期列。我在 PL/SQL 中编写以下查询,但出现错误
group function is not allowed here
delete employees where date = '06-05-2020 'and avg (salary)> 5500;
我该如何解决这个问题?
您的查询毫无意义(至少对我而言)。 平均工资代表什么? 谁的平均工资?
这是一个基于 Scott 的 EMP
table 的示例;我要删除1981年12月3日入职的员工平均工资高于2000的部门
示例数据:
SQL> select deptno, ename, sal, hiredate from emp order by deptno, ename;
DEPTNO ENAME SAL HIREDATE
---------- ---------- ---------- ----------
20 ADAMS 1100 12.01.1983
20 FORD 3000 03.12.1981 --> this
20 JONES 2975 02.04.1981
20 SCOTT 3000 09.12.1982
20 SMITH 800 17.12.1980
30 ALLEN 1600 20.02.1981
30 BLAKE 2850 01.05.1981
30 JAMES 950 03.12.1981 --> this
30 MARTIN 1250 28.09.1981
30 TURNER 1500 08.09.1981
30 WARD 1250 22.02.1981
11 rows selected.
每个部门的平均工资:
SQL> select deptno, avg(sal) avg_salary
2 from emp
3 group by deptno
4 order by avg_salary desc;
DEPTNO AVG_SALARY
---------- ----------
20 2175 --> higher than 2000
30 1566,66667
所以:我正在寻找在 20 部门工作的员工(因为只有那个部门的平均工资高于 2000)并且在 03.12.1981 被录用(James和福特,但只有 Ford 在 20 部门工作):
SQL> delete from emp
2 where hiredate = date '1981-12-03'
3 and deptno in (select deptno
4 from emp
5 group by deptno
6 having avg(sal) > 2000
7 );
1 row deleted.
福特还在吗?
SQL> select * From emp where ename = 'FORD';
no rows selected
SQL>
没有,删了。
现在,轮到你了。