Created
March 26, 2022 15:05
-
-
Save elyasha/916a19a38477e92fb70ff009d1b2dfe5 to your computer and use it in GitHub Desktop.
LEARN SQL Analyze Hacker News Trends
This file contains 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
SELECT title, score | |
FROM hacker_news | |
ORDER BY score DESC | |
LIMIT 5; | |
SELECT SUM(score) FROM hacker_news; | |
SELECT user, SUM(score) FROM hacker_news GROUP BY user HAVING SUM(score) > 200 ORDER BY 2 DESC; | |
SELECT (517 + 309 + 304 + 282) / 6366.0; | |
SELECT user, COUNT(*) FROM hacker_news WHERE url LIKE '%watch?v=dQw4w9WgXcQ%' GROUP BY user; | |
SELECT CASE | |
WHEN url LIKE '%github.com%' THEN 'GitHub' | |
WHEN url LIKE '%medium.com%' THEN 'Medium' | |
WHEN url LIKE '%nytimes.com%' THEN 'New York Times' | |
ELSE 'Other' | |
END AS 'Source', COUNT(*) | |
FROM hacker_news | |
GROUP BY 1; | |
SELECT timestamp | |
FROM hacker_news | |
LIMIT 10; | |
SELECT timestamp, | |
strftime('%H', timestamp) | |
FROM hacker_news | |
GROUP BY 1 | |
LIMIT 20; | |
SELECT strftime('%H', timestamp) AS 'Hour', | |
ROUND(AVG(score), 1) AS 'Average Score', | |
COUNT(*) AS 'Number of Stories' | |
FROM hacker_news | |
WHERE timestamp IS NOT NULL | |
GROUP BY 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment