Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing MySQL to select data from the last three months
    primarykey
    data
    text
    <p>I have a table which contains the following columns:</p> <ul> <li>ID = unique identifier in ascending order</li> <li>ProductId = Id of a product</li> <li>rate1 to rate5 = number of times that product has recived a 1 star, 2 star, 3 star, 4 star or 5 star rating</li> <li>aveRate = average rating for that product</li> <li>lastSubDate = last time a review was submitted for that product</li> </ul> <p>And I'm trying to write an SQL statement which selects the ProductId's which have the highest number of 5 star ratings also with an average rating of 5 and the last review submission was within the last three months.</p> <p>The table looks like this example:</p> <pre><code>ID ProductId rate1 rate2 rate3 rate4 rate5 aveRate lastSubDate 18 9996637 0 0 0 0 1 5 2011-08-10 12:00:34 26 9996628 1 0 0 0 0 1 2010-05-06 05:45:05 34 9996618 0 0 0 1 0 4 2011-10-09 09:00:45 36 9996614 5 0 0 0 0 1 2011-01-05 09:30:32 48 9996592 5 0 1 0 3 3 2012-11-28 19:00:06 66 9996566 0 0 0 1 3 5 2011-04-06 06:45:34 70 9996562 0 0 0 1 1 5 2011-05-17 18:30:03 </code></pre> <p>This is the query I've got so far:</p> <pre><code>SELECT `ProductId`,`rate5`,`aveRate`,`lastSubDate` FROM ratings WHERE `aveRate` = 5 AND `lastSubDate` &gt; '24 Feb 2013' ORDER BY `rate5` DESC LIMIT 3 </code></pre> <p>This returns the products with the most 5 star reviews which also have an average rating of 5, however it doesn't limit the results to the last three months as I want. How can I amend this statement to also select data from only the last three months?</p>
    singulars
    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.
 

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