简体   繁体   中英

How to Combine multiple column into one in php SQL

I have this data. Can someone help how can I combine them into one?

id  employeeID   date         timein    timeout     timein1     timeout1
1   12286        2016-09-10   08:08:00  00:00:00    00:00:00    00:00:00
2   12286        2016-09-10   00:00:00  12:08:32    00:00:00    00:00:00
3   12286        2016-09-10   00:00:00  00:00:00    12:41:54    00:00:00
4   12286        2016-09-10   00:00:00  00:00:00    00:00:00    17:10:05
5   12286        2016-10-10   07:41:05  00:00:00    00:00:00    00:00:00
6   12286        2016-10-10   00:00:00  12:15:00    00:00:00    00:00:00
7   12286        2016-10-10   00:00:00  00:00:00    12:35:15    00:00:00
8   12286        2016-10-10   00:00:00  00:00:00    00:00:00    17:15:15

This is the output that I wanted. Help me. Thanks

id  employeeID   date         timein    timeout     timein1     timeout1
1   12286        2016-09-10   08:08:00  12:08:32    12:41:54    17:10:05
2   12286        2016-10-10   07:41:05  12:15:00    12:35:15    17:15:15

If it was me, I'd probably adopt a schema roughly as follows:

id  employeeID   datetime             activity
1   12286        2016-09-10 08:08:00  in 
2   12286        2016-09-10 12:08:32  out  
3   12286        2016-09-10 12:41:54  in
4   12286        2016-09-10 17:10:05  ...

A temporary solution without field: id

select employeeID, date, max(timein), max(timeout), max(timein1), max(timeout1) group by employeeID, date

Better revise the Insert query to null for 00:00:00 instead

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM