Answers for "how to use row_number()"

SQL
0

row_number example

WITH cte_customers AS (
    SELECT 
        ROW_NUMBER() OVER(
             ORDER BY 
                first_name, 
                last_name
        ) row_num, 
        customer_id, 
        first_name, 
        last_name
     FROM 
        sales.customers
) SELECT 
    customer_id, 
    first_name, 
    last_name
FROM 
    cte_customers
WHERE 
    row_num > 20 AND 
    row_num <= 30;
Code language: SQL (Structured Query Language) (sql)
Posted by: Guest on May-10-2021
0

row_number example

SELECT 
   first_name, 
   last_name, 
   city,
   ROW_NUMBER() OVER (
      PARTITION BY city
      ORDER BY first_name
   ) row_num
FROM 
   sales.customers
ORDER BY 
   city;Code language: SQL (Structured Query Language) (sql)
Posted by: Guest on May-10-2021

Code answers related to "SQL"

Browse Popular Code Answers by Language