I have a table store_visits
with the following structure:
store_visits:
store_name: string
visit_count: integer
visit_date: date
My goal is to create a query that for each store and a given date range, will calculate:
- Average Number of Visits over the date range (currently using
AVG(visit_count)
) - Whether store visits are increasing or decreasing
- The relative rate of increase/decrease (1 to 4 scale where 1 = low rate, 4 = high rate)
The relative rate of increase/decrease in visits is for directional purpose only. It will always be a linear scale.
I've spent a day trying to construct the MySQL query to do this, and just can't get my head around it.
Any help would be greatly appreciated.
Thanks, -Scott