Help with oracle database query

-1

How to increase your salary by 0.1% of those with lower salary than your department's AVG

This is the table for

I was able to take the average salary by department:

SELECT cod_departamento, AVG(VAL_SALARIO)
FROM FUNCIONARIO
GROUP BY COD_DEPARTAMENTO;
    
asked by anonymous 10.02.2018 / 04:47

1 answer

2

To increase the salary of FUNCIONÁRIOS can be done as follows:

1 - Let's see which records will change:

Accordingtotheirdepartment,1,2and3arerequiredrespectivelylessthan~3603,2392and~1973asa%oftheirwagestoincreaseby10%.

2nd-NowweneedtodoVAL_SALARIOintheregistry,thiscanbedonethisway:

UPDATEFUNCIONARIOSFUNCSETFUNC.VAL_SALARIO=FUNC.VAL_SALARIO*1.10WHEREFUNC.VAL_SALARIO<(SELECTAVG(FUNCIO.VAL_SALARIO)FROMFUNCIONARIOSFUNCIOWHEREFUNCIO.COD_DEPARTAMENTO=FUNC.COD_DEPARTAMENTOGROUPBYFUNCIO.COD_DEPARTAMENTO);

NoticethatthesecrethereistheUPDATEwegivetheALIASwhicharethesame,onewecallTABELASandanotherwecallFUNCtodifferentiateonefromtheother,FUNCIOwillbecomparedintheFUNCtable.

So,weupdated4records.

What are the 4 previously spelled out: FUNCIO .

    
10.02.2018 / 13:39