I have these tables here:
and I want to query the store ID with the most purchases in a specific month (any month).
I came up with this query:
SELECT DISTINCT store_id FROM (SELECT store_id, purchase_date FROM purchase where purchase_date >= '2021-04-01' AND purchase_date <= '2021-04-30'
SELECT DISTINCT store)
I am still starting in SQL and I can’t seem to move from here.
2
Answers
you can try this
Assuming that most purchases means highest sales and not the number of sales and purchase_date is not text but of type date:
If you want to just find store with maximum number of purchases and not the Total value of sales: