在SQL中,ROW_NUMBER()是用來給查詢結果集中的每一行分配一個唯一的數字標識符的窗口函數。與其他窗口函數結合使用可以實現不同的功能,例如:
SELECT
*,
ROW_NUMBER() OVER (PARTITION BY category ORDER BY price) AS row_num
FROM products;
SELECT
*,
ROW_NUMBER() OVER (ORDER BY price DESC) AS row_num
FROM products;
SELECT *
FROM (
SELECT
*,
ROW_NUMBER() OVER (ORDER BY id) AS row_num
FROM products
) AS ranked_products
WHERE row_num BETWEEN 5 AND 10;
通過結合ROW_NUMBER()與其他窗口函數,可以實現更加靈活和復雜的查詢需求,提高查詢結果的準確性和可讀性。