Hi,
I'm trying to write a SQL script that should compress a table that has duplicates clients.
For example I have a table with the following format:
id, first_name, last_name, date_of_birth, number_of_sales, contry_id, date_inserted ...
and we have millions of rows with this format. The problem we have is in the following example"
0, John, Smith, 1966-01-01, 5, 53231255, 2020-01-01
1, Mary, Brown, 1956-06-01, 3, 34364363, 2019-04-02
2, John, Smith, 1966-01-01, 7, 12958345, 2021-04-05
here the client in the first row is the same with the client in the third row but they have a different country_id by which they were inserted as unique client. I want to to write a script that should summarize the table with the criteria that they people with the same first/last name and data of birth are the same people and sum up some field like number_of_sales and in some fields that have different values we should save the latest insertion . After the summarization we should have:
1, Mary, Brown, 1956-06-01, 3, 34364363, 2019-04-02
2, John, Smith, 1966-01-01, 13, 12958345, 2021-04-05
I know this is somehow abstract but any suggestion are welcome.
Thank you.