The query is as follows:
Obtain for each department how many employees work, the sum of their salaries and the sum of their commissions for those departments in which there is an employee whose salary is greater than 1700 euros.
I have tried the following order, to start little by little, I want it to tell me how many employees there are in each department, but it gives an error: the group function is not a single group
select count(*), coddpto from empleado order by coddpto
the dept table is:
CODDPTO NUMBER
* DENOMINACION VARCHAR2
F * CODCENTRO NUMBER
CODDPTODEPENDE NUMBER
F * CODEMPLEJEFE NUMBER
* TIPO CHAR
* PRESUPUESTO NUMBER
FK_CODCENTRO (CODCENTRO)
FK_CODEMPLEJEFE (CODEMPLEJEFE)
and the employee table is:
CODEMPLE NUMBER
* APE1 VARCHAR2
* APE2 VARCHAR2
* NOMBRE VARCHAR2
* DIRECCION VARCHAR2
* LOCALIDAD VARCHAR2
TELEF VARCHAR2
* CODDPTO NUMBER
F * CODCATE NUMBER
* FECHAINGRESO DATE
* SALARIO NUMBER
COMISION NUMBER
PK_CODEMPLE (CODEMPLE)
FK_CODCATE (CODCATE)
PK_CODEMPLE (CODEMPLE)
The query from what I understand can be very simple.
In my case, I would apply the 3 grouped in a single query.
An inner join is done to join the employee and department tables by the field that relates them, which in this case is coddpt, then all the employees who have a salary greater than 1700 are filtered by means of a where , then it is grouped by the name of the department , and in this way the name of the department, the number of workers who work in it, the total salary of its workers and the total of its commissions will be selected for each department