作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我在从考勤机拆分数据时遇到问题。导出后的数据源如下:
id name att1 John 01/04/2015 7:59:001 John 01/04/2015 17:44:001 John 02/04/2015 7:50:001 John 02/04/2015 18:14
指纹时间的记录(进出)保存在一列中。我想将数据拆分成这样:
id name in out1 John 01/04/2015 7:59:00 01/04/2015 17:44:001 John 02/04/2015 7:50:00 02/04/2015 18:14:00
如何在 MySQL 或 PHP(可能)中将这些记录拆分为 2 列?谢谢。
最佳答案
假设每天只有一次进出,那么在日期和更大的时间上自行加入就很简单了。
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
如果你想用这些数据创建一个全新的表,这样你就可以摆脱导入,你只需要使用这个查询作为create table
的输入,就像这样:
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
关于php - 在 MysQL 或 PHP 中将记录从一列拆分为两列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30251510/
我是一名优秀的程序员,十分优秀!