I have these tables:
CREATE TABLE IF NOT EXISTS sucursal(
numSucursal int PRIMARY KEY NOT NULL,
nombre VARCHAR(100) NOT NULL,
direccion VARCHAR(100) NOT NULL
);
and this:
CREATE TABLE IF NOT EXISTS empleado(
numEmpleado int PRIMARY KEY NOT NULL,
nombre VARCHAR(100) NOT NULL,
email VARCHAR(100) NOT NULL,
sueldo bigint NOT NULL,
fContratacion DATE NOT NULL,
numSucursal int,
jefe int NULL,
CONSTRAINT fkjefe
FOREIGN KEY (jefe) REFERENCES empleado(numEmpleado),
CONSTRAINT fksucursal
FOREIGN KEY (numSucursal) REFERENCES sucursal(numSucursal)
);
I have to show the average salary of each branch, but I can't find a way to do it, I know how to get the average, but not how to link the employees to a branch exactly.
When creating an employee, I assign the branch number to the field numSucursal
as fk , but the rest does not work for me.
Please help, thank you very much.
I think this may work for you, try it and tell me that I've done it upside down and I haven't tried it