normalization - MySQL Table Design - User Logon Times -


i need provide following data regarding member logins example:

last hour 654 last day 15,648 last week 109,536 last month 460,051 last year 5,520,614 

i wondering best possible structure of table hold information in mysql db.

currently i'm thinking of storing:

user datetime 

i expect large on time , become slow query.

is there better way structure table information on logins - hourly, day, week, month, year etc?

$current_time = strtotime(date('d-m-y g:i:s a'));  $last_hour = $current_time - 3600; $last_day = $current_time - (3600*24); $last_week = strtotime("-1 week"); $last_month = strtotime("-1 month"); $last_year = strtotime("-1 year");  // count  // count last hour $sql = "select count(user_id) cnt `your_table` datetime>='$last_hour' ";  // count last day $sql = "select count(user_id) cnt `your_table` datetime>='$last_day' ";  // count last week $sql = "select count(user_id) cnt `your_table` datetime>='$last_week' ";  // count last month $sql = "select count(user_id) cnt `your_table` datetime>='$last_month' ";  // count last year $sql = "select count(user_id) cnt `your_table` datetime>='$last_year' "; 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -