In my database I have couple of stores and each store has couple of coupons sold and I need to find the rank as per the maximum coupons sold per store. I am using the following SQL code
set @rownum := 0;
SELECT @rownum := @rownum + 1 AS rank, sum(couponscount) as count, restaurant from coupons group by restaurant order by count desc
But, the output doesn't print the rank as per the maximum sum(couponscount) but its printing rank as per the store name alphabetical order.
How can I make it working?
I also need to retrieve the rank of a particular record and I am using the following SQL query for that
set @rownum := 0;
select rank from (SELECT @rownum := @rownum + 1 AS rank, sum(couponscount) as count, restaurant from coupons group by restaurant order by count desc) `storerank` where restaurant='some store name'
So, I need a first SQL query should be compatible with this one as well.
Thanks.