SQLid | ic | party_number | ml | .....
SQLid | party_id | o_time
SQLparty:id | ic | party_number |ml123|140UD17| 55 |321234|140UD17| 55 |321 times:id |party_id|o_time567 | 123 |10000568 | 123 |20000569 | 123 |30000...........................2323| 234 |100002324| 234 |200002325| 234 |300002326| 234 |40000
SQLCREATE TABLE party(id INTEGER PRIMARY KEY AUTOINCREMENT,ic VARCHAR(50) NOT NULL,party_number VARCHAR(15),ml VARCHAR(15)); CREATE TABLE times(id INTEGER PRIMARY KEY AUTOINCREMENT,party_id INTEGER NOT NULL,o_time INTEGER NOT NULL);
SQLDELETE FROM partyWHERE id IN (WITH view_times AS ( SELECT party_id, MAX(o_time) AS o_time FROM times GROUP BY party_id ) SELECT p1.id FROM party AS p1, party AS p2, view_times AS t1, view_times AS t2 WHERE p1.id <> p2.id AND p1.ic = p2.ic AND p1.party_number = p2.party_number AND p1.ml = p2.ml AND p1.id = t1.party_id AND p2.id = t2.party_id AND t1.o_time < t2.o_time )/ DELETE FROM times WHERE party_id NOT IN (SELECT id FROM party)/
SQLDELETE FROM partyWHERE id IN (WITH view_times AS
SQLDELETE FROM [party]WHERE [id] NOT IN ( SELECT [party].[id] FROM [party] JOIN [times] ON [party].[id] = [times].[party_id] GROUP BY [ic], [ml], [party_number] ORDER BY [o_time] DESC); DELETE FROM [times] WHERE [party_id] NOT IN ( SELECT [id] FROM [party] );
SQL...SELECT [party].[id] FROM [party] JOIN [times] ON [party].[id] = [times].[party_id] GROUP BY [ic], [ml], [party_number] ORDER BY [o_time] DESC...
SQLDELETE FROM partyWHERE id IN (SELECT p1.id FROM party AS p1, party AS p2, (SELECT party_id, MAX(o_time) AS o_time FROM times GROUP BY party_id) AS t1, (SELECT party_id, MAX(o_time) AS o_time FROM times GROUP BY party_id) AS t2 WHERE p1.id <> p2.id AND p1.ic = p2.ic AND p1.party_number = p2.party_number AND p1.ml = p2.ml AND p1.id = t1.party_id AND p2.id = t2.party_id AND t1.o_time < t2.o_time )