Recall SQLServer group sort once to reanalyze
row_number() over ( PARTITION BY t1.col_2 ORDER BY 1 )
-- Code
DELETE FROM table_name t
WHERE t.rowid IN (
SELECT rid
FROM(
SELECT t1.rowid rid,row_number() over ( PARTITION BY t1.col_2 ORDER BY 1 ) rn
FROM table_name t1
) t1
WHERE t1.rn > 1
);
-- PARTITION BY t1.col_2
-- The first grouping is based on the second column
-- ORDER BY 1
-- then sort by the first column
-- row_number()
-- reassign row numbers to the grouped sorted data
-- similar to a grouped set of numbers
-- for example, the first two steps are divided into three groups
-- row_number() will renumber the first group from 1, 1.2.3.4 ....
-- the second group will still be numbered from 1, 1.2.3.4 ....
-- and so on down the line
-- WHERE t1.rn > 1
-- Filter the grouped sorted data to filter out all rows numbered greater than 1 (i.e. duplicate rows)
-- keep only the first record, filter all others greater than 1 and then use t.rowid IN () to delete them to achieve de-duplication
Read More:
- MYSQL gruop by Error: this is incompatible with sql_mode=only_full_group_by
- [Solved] MYSQL 5.7 gruop by eRROR: this is incompatible with sql_mode=only_full_group_by
- [MySQL] The principle of group by aggregation function and the reason for aggregation limitation SELECT list is not in GROUP BY clause and contains nonaggregated column
- [Solved] MySQL Error: ERROR 1055 (42000)sql_mode=only_full_group_by
- postgresql-Database query problem-ERROR: column “t.domainid“ must appear in the GROUP BY clause or be used in an a
- How to Solve MySQL version 5.7+ Group by group error
- [Solved] MYSQL Start Project Error: this is incompatible with sql_mode=only_full_group_by
- MySQL OrderBy Error: Expression #1 of ORDER BY
- [Solved] ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregate
- SQL server converts multiple lines into one line, separated by characters
- [Two Methods] Ora-00904: invalid group by error identifier
- [Solved] MySQL Error: “Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre”
- [Solved] The number of rows returned by the mybatis UPDATE statement is always 1 or useaffectedrows = true
- [Solved] MySQL Error: Can‘t find record in ‘order_form‘
- ERROR 1261 (01000): Row 1 doesn‘t contain data for all columns
- Caused by: java.sql.SQLTransientConnectionException: HikariPool-1 – Connection is not available, request timed out after 30005ms.
- [Solved] Caused by: java.sql.SQLException: Access denied for user ‘root‘@‘hadoop102‘ (using password: YES)
- [Solved] Sequelize DatabaseError: ER_WRONG_FIELD_WITH_GROUP: Expression #2 of SELECT list is not in GROUP
- [Solved] Mysql Error: [Err] 1136 – Column count doesn‘t match value count at row 1
- [Solved] MySQL Error: Client does not support authentication protocol requested by server