0

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 2

1

Try this..

SET @row_number:=0;
SELECT @row_number:=@row_number+1 AS row_number,restaurant, sum(couponscount) as position FROM coupons group by restaurant order by rank desc
Sign up to request clarification or add additional context in comments.

Comments

0

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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.