M
M
Michael2010-10-31 17:24:33
MySQL
Michael, 2010-10-31 17:24:33

Need help compiling a Mysql query

There is a table with statistics in it 3 fields (id, time, user_id)

Help to collect one query to select COUNT(id) WHERE time (broken by hours) for the last 7 days grouped by user_id. It's just that I get a terrible footcloth with a bunch of nested queries, maybe there is a more competent solution

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
exIV, 2010-10-31
@exIV

it seems that no subrequest is needed here:
select user_id, DATE_ADD( FROM_DAYS( TO_DAYS( request_time ) ), INTERVAL HOUR(request_time) HOUR ) as rh, count( * ) as cnt from stats
where request_time between DATE_ADD( CURDATE( ), INTERVAL - 7 DAY ) and CURDATE( )
group by by user_id, rh

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question