trying to solve a request from a client I ran into a problem and wanted to know if it is possible to make an sql query with conditionals.
My problem is the following at the moment I have a query that allows me to bring information from 3 tables.
NGRESO: It is the table that has all the registered teams (brand, serial, date of entry, location)
TEAM: It is the table that has the team's resume, it stores the entry index and the movement index (if it has had location movements) and the current state of the team.
MOVEMENT: It is the table that keeps the changes that have been made to the team since it entered the system until the current moment.
My problem is that I have this query:
SELECT equipo.mov_ide, ingreso.ciu_ide, ingreso.zona_ide, ingreso.ofi_ide, ingreso.micro_ide, ingreso.pun_ide, movimiento.ciu_ideD , movimiento.zona_ideD, movimiento.ofi_ideD, movimiento.micro_ideD, movimiento.pun_ideD, equipo.ide_equipo, ingreso.hard_ide, ingreso.af_fec, ingreso.mar_ide, ingreso.mod_ide,ingreso.ide_prov, ingreso.af_ser, ingreso.af_mac, ingreso.af_simcard, equipo.est_equi
FROM equipo
LEFT JOIN ingreso ON (equipo.ide_ing = ingreso.ing_ide AND equipo.ide_equipo = ingreso.ide_equipo)
LEFT JOIN movimiento ON (equipo.mov_ide = movimiento.mov_ide AND equipo.ide_equipo = movimiento.ide_equipo)
and it brings me these results:
Now my problem is that as you see in the image if the first field
equipo.mov_ide
is greater than 0
means that the team had some movement in the location and this will be stored in movimiento.ciu_ideD , movimiento.zona_ideD, movimiento.ofi_ideD, movimiento.micro_ideD, movimiento.pun_ideD
if on the contrary the team has no movements and the first field is zero .. the positions shown are NULL
.
A query could be made that only brings the location of the real equipment.
in this case if the first field equipo.mov_ide
is 0
the real location are the first fields ingreso.ciu_ide, ingreso.zona_ide, ingreso.ofi_ide, ingreso.micro_ide, ingreso.pun_ide
if the first field equipo.mov_ide
is greater than 0
the real location is relative to movement movimiento.ciu_ideD , movimiento.zona_ideD, movimiento.ofi_ideD, movimiento.micro_ideD, movimiento.pun_ideD
Thanks!