I’m back with another mysql query question. This time, given a time range, I need to select the date of the last order of a customer AND the total number of order that customer placed within that time range.
The (stripped) query goes like this:
SELECT
customers_id,
customers_name,
date_purchased,
count(*) as total_order
FROM orders
GROUP BY customers_id;
Obviously the date_purchased returned there is not of the LAST order of the customer within the time range, but I can’t order before group by, is there anyway to get around this? For example should I order first, then group by (nested selects)?
1 Answer