Skip to content

Instantly share code, notes, and snippets.

@RRRoger
Last active March 11, 2022 13:55
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save RRRoger/9b6707eb9f17072349b0bcb924d83f66 to your computer and use it in GitHub Desktop.
重复记录过滤.sql
with main_table as (
...
)
SELECT
a.*
FROM
main_table as a
WHERE
NOT EXISTS
(
SELECT
1
FROM
main_table as b
WHERE
-- main_table的重复字段
a.field1 = b.field1,
a.field2 = b.field2
-- 修改上面
-- 较大的一条 用'<', 较小的一条用'>'
AND a.cmp_field < b.cmp_field
-- 修改上面
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment