如何在mysql中从数据库中获取每小时数据

时间:2013-08-21 09:56:31

标签: mysql

我必须每小时根据日期时间从数据库中获取数据,我尝试了但却无法理解..我是sql的新手,请你帮我。我正在尝试在一小时内为特定用户获取他执行了多少操作的数据

select username,count(message) as '8-9',count(message) as '9-10',count(message) as '10-11'
from customer_1.audit_trail 
inner join inteliviz.user on customer_1.audit_trail.user_id = inteliviz.users.id 
where datetime>'2013-08-21 08:00:00' and datetime<'2013-08-21 09:00:00'
group by username  limit 1000;

1 个答案:

答案 0 :(得分:0)

之间使用
select username,count(message) as '8-9',count(message) as '9-10',count(message) as '10-11'
from customer_1.audit_trail 
inner join inteliviz.user on customer_1.audit_trail.user_id = inteliviz.users.id 
where datetime between '2013-08-21 08:00:00' and '2013-08-21 09:00:00'
group by username  limit 1000;