Moonfrog Interview Questions | Row Number

Question

How to generate row number in a table without using ROWNUM() ?

in progress 0
Dhruv2301 55 years 2 Answers 989 views Great Grand Master 0

Answers ( 2 )

  1. By using Row_Number() window function.
    Example :
    SELECT
    ROW_NUMBER() OVER (
    ORDER BY first_name
    ) row_num,
    first_name,
    last_name,
    city
    FROM
    sales.customers;

  2. ROW_NUMBER() comes under the category of window function. It will number the records based on the condition provided by you. The number will be incremented sequentially irrespective of similar values.

    select emp_name, row_number(order by salary desc) as row_num
    from table

Leave an answer

Browse
Browse