I have a SQL query like SELECT restaurant, sum(couponscount) as position FROMcouponsgroup by restaurant order by rank desc and I want to add serial infront of them so that I can know the rank of the each restaurant by its position.
2 Answers
Select rownum, * from (SELECT restaurant, sum(couponscount) as position FROM coupons group by restaurant order by rank desc);
This would work if u are using oracle DB.
Else
SET @rownum:=0; SELECT @rownum:=@roenum+1 AS rank,restaurant, sum(couponscount) as position FROM coupons group by restaurant order by rank desc;