Split one column record into two columns in MysQL or PHP
I have a problem with the data section from the attendance machine. Data source after exporting from it as follows:
id name att 1 John 01/04/2015 7:59:00 1 John 01/04/2015 17:44:00 1 John 02/04/2015 7:50:00 1 John 04/02/2015 18:14
Where the entry (entry and exit) from the fingerprint time is saved in one column. And I want to split the data like this:
id name in out 1 John 01/04/2015 7:59:00 01/04/2015 17:44:00 1 John 02/04/2015 7:50:00 02/04/2015 18:14:00
How do I split these records into 2 columns in MySQL or PHP (maybe)? Thank.
+3
source to share
2 answers
Assuming there is only one I / O per day, this is as easy as self-connecting on a date and greater time.
select t1.id, t1.name, t1.att as `in`, t2.att as `out`
from table1 t1
inner join table1 t2
on date(t1.att) = date(t2.att) and t1.id = t2.id
and t2.att > t1.att
If you want to create a new table with this data to get rid of the import, you just need to use this query as input create table
, for example:
create table new_table
as
select t1.id, t1.name, t1.att as `in`, t2.att as `out`
from table1 t1
inner join table1 t2
on date(t1.att) = date(t2.att) and t1.id = t2.id
and t2.att > t1.att
+2
source to share