sql

sql的distinct有哪些替代方法

小樊
111
2024-07-11 16:19:26
栏目: 云计算

  1. 使用GROUP BY语句来实现去重功能:
SELECT column1, column2
FROM table_name
GROUP BY column1, column2;
  1. 使用子查询来实现去重功能:
SELECT column1, column2
FROM table_name
WHERE (column1, column2) IN (
    SELECT DISTINCT column1, column2
    FROM table_name
);
  1. 使用窗口函数来实现去重功能:
SELECT DISTINCT column1, column2
FROM (
    SELECT column1, column2, ROW_NUMBER() OVER (PARTITION BY column1, column2 ORDER BY column1) AS rn
    FROM table_name
) AS subquery
WHERE rn = 1;

0
看了该问题的人还看了