I have a table revenue with following fields
+----+-----------+-------------+---------------+
| id | member_id | amount_paid | datetime_paid |
+----+-----------+-------------+---------------+
I want to run a query to find the top 10 maximum revenue days. What would be the fastest way to achieve this? The table has a lot of data.
Regards,
First you need to group the results by the day the payment was made. This can be done by selecting
DATE(datetime_paid) as payday, then grouping bypayday. To get the total, selectSUM(amount_paid) as total. Finally, to get the top 10, order bytotal descandlimit 10.Your final query should look like:
You may need to change that
ORDER BYline toORDER BY SUM(amount_paid) DESC, I can’t remember if field aliases are allowed in ordering.