Note that there are some explanatory texts on larger screens.

plurals
  1. POCumulative average number of records created for specific day of week or date range
    primarykey
    data
    text
    <p>Yeah, so I'm filling out a requirements document for a new client project and they're asking for growth trends and performance expectations calculated from existing data within our database.</p> <p>The best source of data for something like this would be our logs table as we pretty much log every single transaction that occurs within our application.</p> <p>Now, here's the issue, I don't have a whole lot of experience with MySql when it comes to collating cumulative sum and running averages. I've thrown together the following query which kind of makes sense to me, but it just keeps locking up the command console. The thing takes forever to execute and there are only 80k records within the test sample.</p> <p>So, given the following basic table structure:</p> <pre><code>id | action | date_created 1 | 'merp' | 2007-06-20 17:17:00 2 | 'foo' | 2007-06-21 09:54:48 3 | 'bar' | 2007-06-21 12:47:30 ... thousands of records ... 3545 | 'stab' | 2007-07-05 11:28:36 </code></pre> <p>How would I go about calculating the average number of records created for each given day of the week?</p> <pre><code>day_of_week | average_records_created 1 | 234 2 | 23 3 | 5 4 | 67 5 | 234 6 | 12 7 | 36 </code></pre> <p>I have the following query which makes me want to murderdeathkill myself by casting my body down an elevator shaft... and onto some bullets:</p> <pre><code>SELECT DISTINCT(DAYOFWEEK(DATE(t1.datetime_entry))) AS t1.day_of_week, AVG((SELECT COUNT(*) FROM VMS_LOGS t2 WHERE DAYOFWEEK(DATE(t2.date_time_entry)) = t1.day_of_week)) AS average_records_created FROM VMS_LOGS t1 GROUP BY t1.day_of_week; </code></pre> <p>Halps? Please, don't make me cut myself again. :'(</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload