我的环境是fedora 10,安装的是mysql5.1我的问题是:
建立两个表
create table A
(
user_id int not null primary key,
time int not null
//这里里面存放的是linux时间,熟悉linux的都应该知道,是1970年元旦0时0分0秒到现在的秒数
);create table B
(
user_id int not null primary key,
period varchar(10),
count int
);
现在我想将表A的数据经过处理后插入B表,
具体是user_id不需要处理,
通过A表的time判断这个时间分别属于那个时段,比如说(0:00-8:00),下午(8:00-16:00)、晚上(16:00-24:00),
具体是哪一日不必考虑,这个内容放入表B的period项
表B的count项是表A中出现在每个时段的记录的个数。要是这些数据不在数据库中的话我会做的,可以利用linux的时间localtime等函数,但是要想通过一条sql语句实现的话对我来说很有难度,我感觉是不是可以结合shell命令,希望大家可以帮助我,谢谢
建立两个表
create table A
(
user_id int not null primary key,
time int not null
//这里里面存放的是linux时间,熟悉linux的都应该知道,是1970年元旦0时0分0秒到现在的秒数
);create table B
(
user_id int not null primary key,
period varchar(10),
count int
);
现在我想将表A的数据经过处理后插入B表,
具体是user_id不需要处理,
通过A表的time判断这个时间分别属于那个时段,比如说(0:00-8:00),下午(8:00-16:00)、晚上(16:00-24:00),
具体是哪一日不必考虑,这个内容放入表B的period项
表B的count项是表A中出现在每个时段的记录的个数。要是这些数据不在数据库中的话我会做的,可以利用linux的时间localtime等函数,但是要想通过一条sql语句实现的话对我来说很有难度,我感觉是不是可以结合shell命令,希望大家可以帮助我,谢谢
-> '2007-11-30 10:30:19'
from a
group by user_id,ELT(hour(FROM_UNIXTIME(time)) div 8,'0:00-8:00','8:00-16:00','16:00-24:00')
http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
http://topic.csdn.net/u/20100428/09/BC9E0908-F250-42A6-8765-B50A82FE186A.html