diff --git a/hacker_news.csv.sql b/hacker_news.csv.sql index 1ff8bd8..81ddbef 100644 --- a/hacker_news.csv.sql +++ b/hacker_news.csv.sql @@ -1,7 +1,11 @@ .headers on .mode csv .output hacker_news.csv -SELECT id, created_at, time, title, url, author, ndescendants, score, rank -FROM hn_items -WHERE id IN (SELECT hn_id FROM sn_items) -ORDER BY id, created_at DESC; +SELECT hn.id, hn.created_at, hn.time, hn.title, hn.url, hn.author, hn.ndescendants, hn.score, hn.rank +FROM ( + SELECT id, MAX(created_at) AS created_at FROM hn_items + WHERE rank = 1 AND length(title) >= 5 + GROUP BY id + ORDER BY time ASC +) t JOIN hn_items hn ON t.id = hn.id +ORDER BY hn.id, hn.created_at DESC;