How to calculate arrears in mysql

0

hi friends I am trying to calculate the arrears of the teachers ... making the query I get what I want but reviewing the data I get in some fields with null values. Here the consultation:

SELECT th.codigopersonal, tp.nombres, tr.fecha, th.dia, th.j_codigo, 
th.hora_entrada, th.hora_salida, tr.hora_entra, 
tr.hora_sale,th.numero_horas, sec_to_time((time_to_sec (IF((tr.hora_entra > 
th.hora_entrada), (tr.hora_entra - th.hora_entrada),0))))as AtrEntrada, 
SEC_TO_TIME((time_to_sec(IF(tr.hora_sale < th.hora_salida, th.hora_salida-
tr.hora_sale,0))))as AtrSalida
from tb_horarios as th 
left JOIN tb_registroasistencia as tr ON th.codigopersonal=tr.psn_codigo AND 
th.dia= tr.dia AND th.j_codigo=tr.jnd_codigo
LEFT JOIN tb_personal_org as tp ON th.codigopersonal= tp.codigo
WHERE tr.fecha BETWEEN '2018-02-12' AND '2018-02-16'
GROUP BY th.codigopersonal, tr.fecha  
ORDER BY 'tp'.'nombres' ASC

Here are the results of the query:

I hope you can help me!

    
asked by vero m. 20.02.2018 в 17:59
source

1 answer

1

Hello For this you have a function in MySQL called TIMEDIFF and DateDIFF I leave you an example:

SELECT TIMEDIFF('2009-05-18 15:45:57.005678','2009-05-18 13:40:50.005670');

The result of this query is: 02: 05: 07.000008

SELECT TIMEDIFF(HORA_ENTRADA,HORA_FIJADA);

I hope it serves you Memories !!

    
answered by 20.02.2018 / 18:03
source