How could I subtract two values from different tables in SQL? I want a column to subtract the user's vacant days off. These days must be the difference between the days you have requested in the applications and the days you have vacations per year.
I have two tables:
-
solicitud
: which is a request table that has as fieldspk_solicitud
,fk_empleado
,n_diassolicitados
. -
sec_users
: which is a user table withpk_user
,name
,dias_disponibles
.
The fk_empleado
of the request table is the foreign key for pk_user
of the user table.
And I tried this query:
select u.dias_disponibles-s.N_DIASSOLICITADOS as dias_libres
from solicitud s, sec_users u
Once you have already shown me the free days of each user, for example:
Usuario Días libres
============== ==========
Usuario 1 10
Usuario 2 12
Usuario 3 8
Usuario 4 11
I am trying to get him to leave the days he has requested. In the previous function I marked the ones that you have not ordered but now I want the ones you have requested. It would look like this:
Usuario Vacaciones Baja
============== ============ ====
Usuario 1 10 1
Usuario 2 12 0
Usuario 3 8 3
Usuario 4 11 1