-
-
Save leibovic/2305880 to your computer and use it in GitHub Desktop.
Start of a query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Due to limitations of SQLite, we need to make a temp table for this: | |
CREATE TEMP TABLE duped_urls AS | |
SELECT url, SUM(visits) AS total, MAX(modified) AS latest, MAX(_id) AS winner | |
FROM history | |
GROUP BY url | |
HAVING count(url) > 1; | |
UPDATE history | |
SET visits = (SELECT total FROM duped_urls WHERE duped_urls.url=history.url), | |
modified = (SELECT latest FROM duped_urls WHERE duped_urls.url=history.url), | |
deleted = (_id <> (SELECT winner FROM duped_urls WHERE duped_urls.url=history.url)) | |
WHERE url IN (SELECT url FROM duped_urls); | |
DROP TABLE duped_urls; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment