Mysql
 sql >> Database >  >> RDS >> Mysql

Visualizza i valori di datetime in righe diverse in un DataGridView

Puoi utilizzare una query come questa:

SELECT empID, emp_day, MAX(am_in1) as am_in, MAX(am_out1) as am_out, MAX(pm_in1) as pm_in, MAX(pm_out1) as pm_out
FROM (
SELECT empID, DATE_FORMAT(`time_stamp`,'%e') as emp_day,
CASE WHEN am_pm='am' AND in_out='in' THEN DATE_FORMAT(`time_stamp`,'%T') ELSE '' END as am_in1,
CASE WHEN am_pm='am' AND in_out='out' THEN DATE_FORMAT(`time_stamp`,'%T') ELSE '' END as am_out1,
CASE WHEN am_pm='pm' AND in_out='in' THEN DATE_FORMAT(`time_stamp`,'%T') ELSE '' END as pm_in1,
CASE WHEN am_pm='pm' AND in_out='out' THEN DATE_FORMAT(`time_stamp`,'%T') ELSE '' END as pm_out1
FROM attendance
) as o
GROUP BY empID, emp_day

La sottoquery formatta le colonne desiderate e i gruppi di query principali per ottenere una riga per dipendente al giorno.

EDIT:ecco un violino