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

时间:2022-06-27 16:28:17

I have to get the data from database hourly base on datetime ,I tried it but not able to get that idea ..I am new to sql can you help me please. I am trying get data for particular user in an hour how many actions does he performed

我必须根据日期时间从数据库中获取数据,我尝试了但却无法理解..我是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 个解决方案

#1


0  

Use Between

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;

#1


0  

Use Between

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;