0

I want to add specific value to the row number but this statement doesn't work :

SELECT (ROW_NUMBER()+1) OVER(ORDER BY col_1 value DESC) as Row   FROM table

what is the correct syntax to do it ?

1 Answer 1

7

You have to put the addition after the window function, but before the alias.

SELECT ROW_NUMBER() OVER (ORDER BY col_1, value DESC) + 1 as Row   FROM table

... or, you can put it at the beginning if it seems clearer:

SELECT 1 + ROW_NUMBER() OVER (ORDER BY col_1, value DESC) as Row   FROM table

I also added a comma between col1 and value. I assume those are 2 different columns, and that it was a typo. Just mentioning for completeness.

Sign up to request clarification or add additional context in comments.

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.