简体   繁体   中英

Getting average number of uploads (or something else) per day

Sorry if I'm using the wrong SE network for this question.

I'm in need of fetching the average number of uploads and registrations to my website per day. The problem is that I can't seem to figure out the math for this task. In my database tables for uploads and registrations, I have columns which indicate when the row was created, which stores an UNIX timestamp.

How would I calculate the average number of rows created per day?

select avg(anz) from (
    select
    date(from_unixtime(your_TS_column)) as my_date,
    count(*) as anz
    from
    your_table
    group by my_date
) subquery_alias

您可以找到行数并按上传天数进行过滤,我认为您的查询应该是这样,

Select count(*) no_of_uploads FROM UPLOAD_TABLE_NAME WHERE 1 AND OTHER_CONDITIONS GROUP BY DAY(UPLOAD_DATE)

you can try to see how many record in your table and divide the number by the cont of the days the code will be

$q=mysql_query("SELECT * FROM `your_table`;");
$n=mysql_num_rows($q);


$d=mysql_query("SELECT * FROM `your_table` GROUP BY DATE(`date_column`);");
$m=mysql_num_rows($d);
echo ($n/$m);

Some very random answers here with no explanation. So to answer your question it seems like you need the maths for average uploads and average registrations?

You will need first day, total registrations and total uploads. $total_uploads and $total_registrations needs to be fetched from database

$first_day = strtotime("01-01-2013"); //if you want to average from the first of january 2013
$time = time(); //current time

$total_days = ($time - $first_day) / 60 / 60 / 24; //gives you total days
$average_registrations = $total_registrations / $total_days;
$average_uploads = $total_uploads / $total_days;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM