Stack Overflow’s forum is dead but the company’s still kicking

Hacker News Top News

Summary

Stack Overflow's forum has seen a decline in questions due to the rise of AI like ChatGPT, but the company remains resilient by leveraging AI itself. The article discusses the trend and provides data analysis.

No content available
Original Article
View Cached Full Text

Cached at: 05/26/26, 06:56 PM

# Stack Overflow’s forum is dead thanks to AI, but the company’s still kicking… thanks to AI – Sherwood News (and a few links on SEDE – Stack Exchange Data Explorer) Source: [https://wiert.me/2026/05/26/stack-overflows-forum-is-dead-thanks-to-ai-but-the-companys-still-kicking-thanks-to-ai-sherwood-news/](https://wiert.me/2026/05/26/stack-overflows-forum-is-dead-thanks-to-ai-but-the-companys-still-kicking-thanks-to-ai-sherwood-news/) Interesting article: \[[Wayback](https://web.archive.org/web/20260115160923/https://sherwood.news/tech/stack-overflow-forum-dead-thanks-ai-but-companys-still-kicking-ai/)/[Archive](https://archive.is/2026.01.08-214223/https://sherwood.news/tech/stack-overflow-forum-dead-thanks-ai-but-companys-still-kicking-ai/)\][Stack Overflow’s forum is dead thanks to AI, but the company’s still kicking… thanks to AI – Sherwood News](https://sherwood.news/tech/stack-overflow-forum-dead-thanks-ai-but-companys-still-kicking-ai/)\. with this important quote: > The complex questions still get asked on Stack because there’s no other place\. If the LLMs are only as good as the data, which is typically human curated, we’re one of the best places for that, if not the best for technology\. I wonder about how far it has declined now, and also think these are reasons for the decline as well: - a lot of fundamental questions for each topic have already been asked - few new programming languages gained popularity over the last decade \(I think golang was the last major one\) - discussions on GitHub and to a lesser extent GitLab have taken over a lot of traffic - toxic behaviours on mainly the Stack overflow and meta site I mentioned in[The toxic reactions to “What would be good alternatives to Stack Overflow for questions about software solutions to drive hardware? – Meta Stack Overflow”](https://wiert.wordpress.com/?p=159088) Anyway, the graph in that post is just a sexy version of a query you can create yourself on the SEDE \(Stack Exchange Data Explorer\)\. That’s why I included both below\. > ![Graph: Stack Overflow's Forum's Decline Started Years Ago, But Al Killed The Platform For Good; Horizontal data: year; Vertical data: Number Of Questions Asked [Monthly, including deleted questions]; Rise from 2008-24, peak during Covid-19 in 2021/2022, decline from 2024 when ChatGPT got launched](https://wiert.me/wp-content/uploads/2026/01/0268e1ddfe137f49.png) Graph: Stack Overflow’s Forum’s Decline Started Years Ago, But Al Killed The Platform For Good; Horizontal data: year; Vertical data: Number Of Questions Asked \[Monthly, including deleted questions\]; Rise from 2008\-24, peak during Covid\-19 in 2021/2022, decline from 2024 when ChatGPT got launched If you are like me, you also want other measures, like seeing answers and comments: are these also dropping, if so do they drop at the same rate, and what’s the ratio over time of answers over questions, and comments over questions and answers? ### Generating graphs like these yourself If you want to regenerate a very similar graph, check out the query \[[Archive](https://archive.is/2026.01.15-175821/https://data.stackexchange.com/stackoverflow/revision/1932522/2374035/questions-per-month-including-deleted)\][Questions per month including deleted – Stack Exchange Data Explorer](https://data.stackexchange.com/stackoverflow/revision/1932522/2374035/questions-per-month-including-deleted) > ``` SELECT DATEFROMPARTS(YEAR(CreationDate), MONTH(CreationDate), 1) AS [Month], COUNT(*) AS [Questions] FROM PostsWithDeleted WHERE PostTypeId = 1 GROUP BY DATEFROMPARTS(YEAR(CreationDate), MONTH(CreationDate), 1) ORDER BY [Month] ASC ``` That was my starting point after a quick search, and the base of all my queries below\. The above query resulted in this graph: \[[Archive](https://archive.is/2026.01.15-165347/https://data.stackexchange.com/stackoverflow/revision/1932522/2374035/questions-per-month-including-deleted%23graph)\][Questions per month including deleted – Stack Exchange Data Explorer \(graph\)](https://data.stackexchange.com/stackoverflow/revision/1932522/2374035/questions-per-month-including-deleted#graph) > ![](https://web.archive.org/web/20260115180251if_/https://private-user-images.githubusercontent.com/2033367/536362203-4db75341-a0c7-4b64-a6ec-e67f80575005.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njg1MDA0NTMsIm5iZiI6MTc2ODUwMDE1MywicGF0aCI6Ii8yMDMzMzY3LzUzNjM2MjIwMy00ZGI3NTM0MS1hMGM3LTRiNjQtYTZlYy1lNjdmODA1NzUwMDUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDExNSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAxMTVUMTgwMjMzWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YTFkMGYxZWVlMTk3OWIyZDE1Y2FhYmMwNmZlODJhM2ZhOTY5NDc0NzI1ZGRlZWE1MzNlMTQ2Y2JhNWQ4N2Y2YiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.4bOZP0e_zWrUHxKt04gsvwC8kl7ktKDdRpJAdmyp90c) \[[Wayback](https://web.archive.org/web/20260115180251/https://private-user-images.githubusercontent.com/2033367/536362203-4db75341-a0c7-4b64-a6ec-e67f80575005.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njg1MDA0NTMsIm5iZiI6MTc2ODUwMDE1MywicGF0aCI6Ii8yMDMzMzY3LzUzNjM2MjIwMy00ZGI3NTM0MS1hMGM3LTRiNjQtYTZlYy1lNjdmODA1NzUwMDUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDExNSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAxMTVUMTgwMjMzWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YTFkMGYxZWVlMTk3OWIyZDE1Y2FhYmMwNmZlODJhM2ZhOTY5NDc0NzI1ZGRlZWE1MzNlMTQ2Y2JhNWQ4N2Y2YiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.4bOZP0e_zWrUHxKt04gsvwC8kl7ktKDdRpJAdmyp90c)/[Archive](https://archive.is/2026.01.15-180250/https://private-user-images.githubusercontent.com/2033367/536362203-4db75341-a0c7-4b64-a6ec-e67f80575005.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njg1MDA0NTMsIm5iZiI6MTc2ODUwMDE1MywicGF0aCI6Ii8yMDMzMzY3LzUzNjM2MjIwMy00ZGI3NTM0MS1hMGM3LTRiNjQtYTZlYy1lNjdmODA1NzUwMDUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDExNSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAxMTVUMTgwMjMzWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YTFkMGYxZWVlMTk3OWIyZDE1Y2FhYmMwNmZlODJhM2ZhOTY5NDc0NzI1ZGRlZWE1MzNlMTQ2Y2JhNWQ4N2Y2YiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.4bOZP0e_zWrUHxKt04gsvwC8kl7ktKDdRpJAdmyp90c)\][536362203\-4db75341\-a0c7\-4b64\-a6ec\-e67f80575005\.png \(1003×535\)](https://private-user-images.githubusercontent.com/2033367/536362203-4db75341-a0c7-4b64-a6ec-e67f80575005.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njg1MDA0NTMsIm5iZiI6MTc2ODUwMDE1MywicGF0aCI6Ii8yMDMzMzY3LzUzNjM2MjIwMy00ZGI3NTM0MS1hMGM3LTRiNjQtYTZlYy1lNjdmODA1NzUwMDUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDExNSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAxMTVUMTgwMjMzWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YTFkMGYxZWVlMTk3OWIyZDE1Y2FhYmMwNmZlODJhM2ZhOTY5NDc0NzI1ZGRlZWE1MzNlMTQ2Y2JhNWQ4N2Y2YiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.4bOZP0e_zWrUHxKt04gsvwC8kl7ktKDdRpJAdmyp90c) ### Answers per month including deleted The is a similar graph as the above one, but now showing answers instead of questions derived from the above Questions query:[Answers per month including deleted – Stack Exchange Data Explorer](https://data.stackexchange.com/stackoverflow/query/1933385/answers-per-month-including-deleted): > ![](https://web.archive.org/web/20260118120041if_/https://private-user-images.githubusercontent.com/2033367/537280204-e8929110-74f7-4fd5-a327-aaf32d270914.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njg3Mzc5MjQsIm5iZiI6MTc2ODczNzYyNCwicGF0aCI6Ii8yMDMzMzY3LzUzNzI4MDIwNC1lODkyOTExMC03NGY3LTRmZDUtYTMyNy1hYWYzMmQyNzA5MTQucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDExOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAxMThUMTIwMDI0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YWM4ZTI0YTU1Yjk5ZjZlM2I4OGY3ZDdiNjRlODg3NTYxYWJjY2YzMmE4MDEwZGEwYzgyNWYzYTFkYmUwNjU4MCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.D5x-xHmhCq96Qhbdec8b0hIySr-B7F1wf6FPIXv_qAk) \[[Wayback](https://web.archive.org/web/20260118120041/https://private-user-images.githubusercontent.com/2033367/537280204-e8929110-74f7-4fd5-a327-aaf32d270914.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njg3Mzc5MjQsIm5iZiI6MTc2ODczNzYyNCwicGF0aCI6Ii8yMDMzMzY3LzUzNzI4MDIwNC1lODkyOTExMC03NGY3LTRmZDUtYTMyNy1hYWYzMmQyNzA5MTQucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDExOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAxMThUMTIwMDI0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YWM4ZTI0YTU1Yjk5ZjZlM2I4OGY3ZDdiNjRlODg3NTYxYWJjY2YzMmE4MDEwZGEwYzgyNWYzYTFkYmUwNjU4MCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.D5x-xHmhCq96Qhbdec8b0hIySr-B7F1wf6FPIXv_qAk)/[Archive](https://archive.is/2026.01.18-120042/https://private-user-images.githubusercontent.com/2033367/537280204-e8929110-74f7-4fd5-a327-aaf32d270914.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njg3Mzc5MjQsIm5iZiI6MTc2ODczNzYyNCwicGF0aCI6Ii8yMDMzMzY3LzUzNzI4MDIwNC1lODkyOTExMC03NGY3LTRmZDUtYTMyNy1hYWYzMmQyNzA5MTQucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDExOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAxMThUMTIwMDI0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YWM4ZTI0YTU1Yjk5ZjZlM2I4OGY3ZDdiNjRlODg3NTYxYWJjY2YzMmE4MDEwZGEwYzgyNWYzYTFkYmUwNjU4MCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.D5x-xHmhCq96Qhbdec8b0hIySr-B7F1wf6FPIXv_qAk)\][537280204\-e8929110\-74f7\-4fd5\-a327\-aaf32d270914\.png \(983×566\)](https://private-user-images.githubusercontent.com/2033367/537280204-e8929110-74f7-4fd5-a327-aaf32d270914.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njg3Mzc5MjQsIm5iZiI6MTc2ODczNzYyNCwicGF0aCI6Ii8yMDMzMzY3LzUzNzI4MDIwNC1lODkyOTExMC03NGY3LTRmZDUtYTMyNy1hYWYzMmQyNzA5MTQucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDExOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAxMThUMTIwMDI0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YWM4ZTI0YTU1Yjk5ZjZlM2I4OGY3ZDdiNjRlODg3NTYxYWJjY2YzMmE4MDEwZGEwYzgyNWYzYTFkYmUwNjU4MCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.D5x-xHmhCq96Qhbdec8b0hIySr-B7F1wf6FPIXv_qAk) The query is different in just two places: the`count\(\*\)`alias and the`PostTypeId`value\. > ``` SELECT DATEFROMPARTS(YEAR(CreationDate), MONTH(CreationDate), 1) AS [Month], COUNT(*) AS [Answers] FROM PostsWithDeleted WHERE PostTypeId = 2 GROUP BY DATEFROMPARTS(YEAR(CreationDate), MONTH(CreationDate), 1) ORDER BY [Month] ASC ``` That opened a quest to get this graph: ### Combined graph adding all post types What I needed for this is aggregate the various post types \(question, answer\) and group by month\. This is a tad more complex than`Count\(\*\) where PostTypeId=\#`queries above\. So I did some digging, where the results… were NOT from the Stack Exchange network \(: I started looking for transaction types and months because I know that is a common scenario in databases\.[Google Search](https://en.wikipedia.org/wiki/Google_Search)returned relevant results, but[Duck Duck Go](https://en.wikipedia.org/wiki/DuckDuckGo)didn’t\. - \[[WaybackFailed](https://web.archive.org/web/20260118110841/https://www.google.com/search?q=sql+count+transaction+types+group+by+month)/[ArchiveSave](https://archive.is/?run=1&url=https://www.google.com/search?q=sql+count+transaction+types+group+by+month)\] \(Cannot be archived\)[sql count transaction types group by month – Google Search](https://www.google.com/search?q=sql+count+transaction+types+group+by+month) - \[[Wayback](https://web.archive.org/web/20260118110820/https://html.duckduckgo.com/html?q=sql+count+transaction+types+group+by+month)/[Archive](https://archive.is/2026.01.18-110846/https://html.duckduckgo.com/html?q=sql+count+transaction+types+group+by+month)\][sql count transaction types group by month at DuckDuckGo](https://html.duckduckgo.com/html?q=sql+count+transaction+types+group+by+month)had no good results - \[[Wayback](https://web.archive.org/web/20210228075240/https://p2p.wrox.com/sql-server-2000/49092-sql-query-generate-counts-month.html)/[Archive](https://archive.is/2026.01.18-110010/https://p2p.wrox.com/sql-server-2000/49092-sql-query-generate-counts-month.html)\][sql query to generate counts by month](https://p2p.wrox.com/sql-server-2000/49092-sql-query-generate-counts-month.html)\(no more recent Wayback Machine archivals because of \#ThisIsWhyWeCantHaveNiceThings with JavaScript and URL rewrites\) > You can do some things with “GROUPING” \(not included below\) to make the subtotals and totals more apparent but, considering you posted no schema nor data, this should get you started once you make the appropriate substitutions for table and column names as required… `SELECT d\.Company,` `d\.\[Year\],` `SUM\(CASE WHEN \[Month\] = 01 THEN Transactions ELSE 0 END\) AS Jan,` `SUM\(CASE WHEN \[Month\] = 02 THEN Transactions ELSE 0 END\) AS Feb,` `SUM\(CASE WHEN \[Month\] = 03 THEN Transactions ELSE 0 END\) AS Mar,` `SUM\(CASE WHEN \[Month\] = 04 THEN Transactions ELSE 0 END\) AS Apr,` `SUM\(CASE WHEN \[Month\] = 05 THEN Transactions ELSE 0 END\) AS May,` `SUM\(CASE WHEN \[Month\] = 06 THEN Transactions ELSE 0 END\) AS Jun,` `SUM\(CASE WHEN \[Month\] = 07 THEN Transactions ELSE 0 END\) AS Jul,` `SUM\(CASE WHEN \[Month\] = 08 THEN Transactions ELSE 0 END\) AS Aug,` `SUM\(CASE WHEN \[Month\] = 09 THEN Transactions ELSE 0 END\) AS Sep,` `SUM\(CASE WHEN \[Month\] = 10 THEN Transactions ELSE 0 END\) AS Oct,` `SUM\(CASE WHEN \[Month\] = 11 THEN Transactions ELSE 0 END\) AS Nov,` `SUM\(CASE WHEN \[Month\] = 12 THEN Transactions ELSE 0 END\) AS \[Dec\],` `SUM\(Transactions\) AS Total,` `SUM\(Transactions\)/24 AS Average` `FROM \(\-\-Derived table "d" finds count for year and month` `SELECT Company,` `\[Year\] = DATEPART\(yy,TransactionDate\),` `\[Month\] = DATEPART\(mm,TransactionDate\)` `Transactions = COUNT\(\*\)` `FROM yourtable` `GROUP BY Company,` `DATEPART\(yy,TransactionDate\),` `DATEPART\(mm,TransactionDate\)` `\) d` `GROUP BY d\.Company,` `d\.\[Year\]` `WITH ROLLUP` `ORDER BY d\.Company,` `d\.\[Year\]` …and, in a properly indexed environment, will process millions of rows in scant seconds \(ie\. 4 million rows in about 5\-7 seconds\)\. –Jeff Moden - \[[Wayback](https://web.archive.org/web/20260118105934/https://datasciencewallah.medium.com/how-to-summarize-monthly-transactions-by-country-in-sql-step-by-step-guide-977b0dcb77ff)/[Archive](https://archive.is/2026.01.18-110803/https://datasciencewallah.medium.com/how-to-summarize-monthly-transactions-by-country-in-sql-step-by-step-guide-977b0dcb77ff)\][How to Summarize Monthly Transactions by Country in SQL \| Step\-by\-Step Guide \| by Data Science Wallah \| Medium](https://datasciencewallah.medium.com/how-to-summarize-monthly-transactions-by-country-in-sql-step-by-step-guide-977b0dcb77ff) > In this tutorial, we will solve the SQL problem**“Monthly Transactions I”**from LeetCode\. This problem will test your skills in grouping data by date and country, as well as filtering and aggregating transaction data based on specific conditions\. This is an excellent problem for practicing SQL aggregation functions like`COUNT\(\)`,`SUM\(\)`, and`GROUP BY`\. … Here’s the complete SQL query to solve the problem: ``` SELECT DATE_FORMAT(trans_date, '%Y-%m') AS month, country, COUNT(*) AS trans_count, SUM(CASE WHEN state = 'approved' THEN 1 ELSE 0 END) AS approved_count, SUM(amount) AS trans_total_amount, SUM(CASE WHEN state = 'approved' THEN amount ELSE 0 END) AS approved_total_amount FROM Transactions GROUP BY DATE_FORMAT(trans_date, '%Y-%m'), country; ``` The tricks used/knowledge needed: - Combine`SUM`and`CASE WHEN`to count relevant values as there is nou`COUNT\(WHEN …\)` - `GROUP BY`cannot use aliases from the`SELECT`portion So in order to get the counts for the various PostTypes, we need to add a column that counts for each PostTypes value\. The`PostTypes`are these \(thanks \[[Wayback](https://web.archive.org/web/20250813192032/https://data.stackexchange.com/stackoverflow/query/36599/show-all-types)/[Archive](https://archive.is/2025.08.13-192032/https://data.stackexchange.com/stackoverflow/query/36599/show-all-types)\][Show all types – Stack Exchange Data Explorer](https://data.stackexchange.com/stackoverflow/query/36599/show-all-types), see more about it further below\): > ``` Id PostType ---- ------------------- 1 Question 2 Answer 3 Wiki 4 TagWikiExcerpt 5 TagWiki 6 ModeratorNomination 7 WikiPlaceholder 8 PrivilegeWiki ``` That resulted in this query:[Questions, answers and other post types per month including deleted – Stack Exchange Data Explorer](https://data.stackexchange.com/stackoverflow/revision/1933447/2375006/questions-answers-and-other-post-types-per-month-including-deleted)\(3 seconds\) > ``` SELECT DATEFROMPARTS(YEAR(CreationDate), MONTH(CreationDate), 1) AS [Month], SUM(CASE WHEN PostTypeId = 1 THEN 1 ELSE 0 END) AS [Questions], SUM(CASE WHEN PostTypeId = 2 THEN 1 ELSE 0 END) AS [Answers], SUM(CASE WHEN PostTypeId = 3 THEN 1 ELSE 0 END) AS [Wikis], SUM(CASE WHEN PostTypeId = 4 THEN 1 ELSE 0 END) AS [TagWikiExcerpts], SUM(CASE WHEN PostTypeId = 5 THEN 1 ELSE 0 END) AS [TagWikis], SUM(CASE WHEN PostTypeId = 6 THEN 1 ELSE 0 END) AS [ModeratorNominations], SUM(CASE WHEN PostTypeId = 7 THEN 1 ELSE 0 END) AS [WikiPlaceholders], SUM(CASE WHEN PostTypeId = 8 THEN 1 ELSE 0 END) AS [PrivilegeWikis], COUNT(*) AS [AllPostTypes] FROM PostsWithDeleted GROUP BY DATEFROMPARTS(YEAR(CreationDate), MONTH(CreationDate), 1) ORDER BY [Month] ASC ``` with this graph: > ![Questions, Answers, Wikis TagWikiExcerpts, TagWikis, ModerationNominations, WikiPlaceholders, PrivilegeWikis, AllPostTypes including deleted ones per month](https://web.archive.org/web/20260122164303if_/https://private-user-images.githubusercontent.com/2033367/539268768-c1955f6e-70b2-4025-8a2b-02534b08f720.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NjkxMDA0NzEsIm5iZiI6MTc2OTEwMDE3MSwicGF0aCI6Ii8yMDMzMzY3LzUzOTI2ODc2OC1jMTk1NWY2ZS03MGIyLTQwMjUtOGEyYi0wMjUzNGIwOGY3MjAucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDEyMiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAxMjJUMTY0MjUxWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9Y2YzNTc3YTg2OTQ2ZWE2OWRkZDZlYmQ4OGI2OGY2NjQyMmFhZmU4Mzk1YzI1ZDBlOTM2Nzc4MmRkOTNkOTRkNCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.DWE6PHE07-SL2Z8bjnLwkhT19XBqwS8gfssMx9bBC5A) Questions, Answers, Wikis TagWikiExcerpts, TagWikis, ModerationNominations, WikiPlaceholders, PrivilegeWikis, AllPostTypes including deleted ones per month \[[Wayback](https://web.archive.org/web/20260122164303/https://private-user-images.githubusercontent.com/2033367/539268768-c1955f6e-70b2-4025-8a2b-02534b08f720.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NjkxMDA0NzEsIm5iZiI6MTc2OTEwMDE3MSwicGF0aCI6Ii8yMDMzMzY3LzUzOTI2ODc2OC1jMTk1NWY2ZS03MGIyLTQwMjUtOGEyYi0wMjUzNGIwOGY3MjAucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDEyMiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAxMjJUMTY0MjUxWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9Y2YzNTc3YTg2OTQ2ZWE2OWRkZDZlYmQ4OGI2OGY2NjQyMmFhZmU4Mzk1YzI1ZDBlOTM2Nzc4MmRkOTNkOTRkNCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.DWE6PHE07-SL2Z8bjnLwkhT19XBqwS8gfssMx9bBC5A)/[Archive](https://archive.is/2026.01.18-172450/https://private-user-images.githubusercontent.com/2033367/537308568-9d4602eb-be19-4699-ad55-9dc08c1cff73.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njg3NTczNzQsIm5iZiI6MTc2ODc1NzA3NCwicGF0aCI6Ii8yMDMzMzY3LzUzNzMwODU2OC05ZDQ2MDJlYi1iZTE5LTQ2OTktYWQ1NS05ZGMwOGMxY2ZmNzMucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDExOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAxMThUMTcyNDM0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZGJjM2I0YTI0MWNiMDJkZWQ2ZGRkY2Y2ZTE2YmE2YjQ3NDBkMzMwODA0ZDMxMmUyZjU0NmJkZmFiZTYwZjI0NSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.1ydgzMlpe3PJP04YPVcQTZ2kKskqzkXbwh5Nv2o1hVg)\][539268768\-c1955f6e\-70b2\-4025\-8a2b\-02534b08f720\.png \(979×525\)](https://private-user-images.githubusercontent.com/2033367/539268768-c1955f6e-70b2-4025-8a2b-02534b08f720.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NjkxMDA0NzEsIm5iZiI6MTc2OTEwMDE3MSwicGF0aCI6Ii8yMDMzMzY3LzUzOTI2ODc2OC1jMTk1NWY2ZS03MGIyLTQwMjUtOGEyYi0wMjUzNGIwOGY3MjAucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDEyMiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAxMjJUMTY0MjUxWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9Y2YzNTc3YTg2OTQ2ZWE2OWRkZDZlYmQ4OGI2OGY2NjQyMmFhZmU4Mzk1YzI1ZDBlOTM2Nzc4MmRkOTNkOTRkNCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.DWE6PHE07-SL2Z8bjnLwkhT19XBqwS8gfssMx9bBC5A) This also gives a rough view of answers per question: until roughly 2018, that was above 1, and from 2020 on it got below 1\. ### Comments by month graph In created this to try creating a second “combined” graph below\. The query is this:[Comments count by Month – Stack Exchange Data Explorer](https://data.stackexchange.com/stackoverflow/query/1933642/comments-count-by-month) > ``` SELECT DATEFROMPARTS(YEAR(Comments.CreationDate), MONTH(Comments.CreationDate), 1) AS [Month], COUNT(Id) AS CommentIdCount FROM Comments GROUP BY DATEFROMPARTS(YEAR(Comments.CreationDate), MONTH(Comments.CreationDate), 1) ORDER BY [Month] ASC ``` and the graph: > ![CommentIdCount by month](https://web.archive.org/web/20260119154001if_/https://private-user-images.githubusercontent.com/2033367/537654387-b7af32a9-68ef-4b06-be89-a36dc620f105.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njg4Mzc0ODcsIm5iZiI6MTc2ODgzNzE4NywicGF0aCI6Ii8yMDMzMzY3LzUzNzY1NDM4Ny1iN2FmMzJhOS02OGVmLTRiMDYtYmU4OS1hMzZkYzYyMGYxMDUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDExOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAxMTlUMTUzOTQ3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9Njc3MzU5NmM1ZTEyM2FlMGU4ZGVmMzhlODk2Y2NiZGI1MGM0MzJkNTkyMmQzYjM5MGY1Y2EzZWZmYjg3Njc2OSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.LFSoL4NGz-RVvdN4jTQumeEpRw9GtbC3sVqpZt2dwxQ) CommentIdCount by month \[[Wayback](https://web.archive.org/web/20260119154001/https://private-user-images.githubusercontent.com/2033367/537654387-b7af32a9-68ef-4b06-be89-a36dc620f105.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njg4Mzc0ODcsIm5iZiI6MTc2ODgzNzE4NywicGF0aCI6Ii8yMDMzMzY3LzUzNzY1NDM4Ny1iN2FmMzJhOS02OGVmLTRiMDYtYmU4OS1hMzZkYzYyMGYxMDUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDExOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAxMTlUMTUzOTQ3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9Njc3MzU5NmM1ZTEyM2FlMGU4ZGVmMzhlODk2Y2NiZGI1MGM0MzJkNTkyMmQzYjM5MGY1Y2EzZWZmYjg3Njc2OSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.LFSoL4NGz-RVvdN4jTQumeEpRw9GtbC3sVqpZt2dwxQ)/[Archive](https://archive.is/2026.01.19-154006/https://private-user-images.githubusercontent.com/2033367/537654387-b7af32a9-68ef-4b06-be89-a36dc620f105.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njg4Mzc0ODcsIm5iZiI6MTc2ODgzNzE4NywicGF0aCI6Ii8yMDMzMzY3LzUzNzY1NDM4Ny1iN2FmMzJhOS02OGVmLTRiMDYtYmU4OS1hMzZkYzYyMGYxMDUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDExOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAxMTlUMTUzOTQ3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9Njc3MzU5NmM1ZTEyM2FlMGU4ZGVmMzhlODk2Y2NiZGI1MGM0MzJkNTkyMmQzYjM5MGY1Y2EzZWZmYjg3Njc2OSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.LFSoL4NGz-RVvdN4jTQumeEpRw9GtbC3sVqpZt2dwxQ)\][537654387\-b7af32a9\-68ef\-4b06\-be89\-a36dc620f105\.png \(979×523\)](https://private-user-images.githubusercontent.com/2033367/537654387-b7af32a9-68ef-4b06-be89-a36dc620f105.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njg4Mzc0ODcsIm5iZiI6MTc2ODgzNzE4NywicGF0aCI6Ii8yMDMzMzY3LzUzNzY1NDM4Ny1iN2FmMzJhOS02OGVmLTRiMDYtYmU4OS1hMzZkYzYyMGYxMDUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDExOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAxMTlUMTUzOTQ3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9Njc3MzU5NmM1ZTEyM2FlMGU4ZGVmMzhlODk2Y2NiZGI1MGM0MzJkNTkyMmQzYjM5MGY1Y2EzZWZmYjg3Njc2OSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.LFSoL4NGz-RVvdN4jTQumeEpRw9GtbC3sVqpZt2dwxQ) ### Combined graph adding comments to all post types The above question/answer ratio estimate got me thinking: what about comments and the ratio to posts – how did these evolve over time? The last query above took about 3 seconds\. The final one about 7 seconds as it needs two more queries, as you can see in[Comments for questions, answers and other posts per month including deleted – Stack Exchange Data Explorer](https://data.stackexchange.com/stackoverflow/query/1933489/comments-for-questions-answers-and-other-posts-per-month-including-deleted): > ``` WITH PostCommentCounts AS ( SELECT COUNT(Id) AS CommentIdCount, PostId FROM Comments GROUP BY PostId ) SELECT DATEFROMPARTS(YEAR(PostsWithDeleted.CreationDate), MONTH(PostsWithDeleted.CreationDate), 1) AS [Month], SUM(CASE WHEN PostTypeId = 1 THEN 1 ELSE 0 END) AS [Questions], SUM(CASE WHEN PostTypeId = 2 THEN 1 ELSE 0 END) AS [Answers], SUM(CASE WHEN PostTypeId = 3 THEN 1 ELSE 0 END) AS [Wikis], SUM(CASE WHEN PostTypeId = 4 THEN 1 ELSE 0 END) AS [TagWikiExcerpts], SUM(CASE WHEN PostTypeId = 5 THEN 1 ELSE 0 END) AS [TagWikis], SUM(CASE WHEN PostTypeId = 6 THEN 1 ELSE 0 END) AS [ModeratorNominations], SUM(CASE WHEN PostTypeId = 7 THEN 1 ELSE 0 END) AS [WikiPlaceholders], SUM(CASE WHEN PostTypeId = 8 THEN 1 ELSE 0 END) AS [PrivilegeWikis], SUM(PostCommentCounts.CommentIdCount) AS [Comments], COUNT(PostsWithDeleted.Id) AS [AllPostTypes] FROM PostsWithDeleted LEFT JOIN PostCommentCounts ON PostCommentCounts.PostId = PostsWithDeleted.Id GROUP BY DATEFROMPARTS(YEAR(PostsWithDeleted.CreationDate), MONTH(PostsWithDeleted.CreationDate), 1) ORDER BY [Month] ASC ``` with this graph: > ![Comments for the Questions, Answers, Wikis TagWikiExcerpts, TagWikis, ModerationNominations, WikiPlaceholders, PrivilegeWikis, AllPostTypes including deleted ones per month (correlated by post)](https://web.archive.org/web/20260118201926if_/https://private-user-images.githubusercontent.com/2033367/537322714-a43a36be-4a30-421a-8235-74d7d865a0cb.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njg3Njc4MzcsIm5iZiI6MTc2ODc2NzUzNywicGF0aCI6Ii8yMDMzMzY3LzUzNzMyMjcxNC1hNDNhMzZiZS00YTMwLTQyMWEtODIzNS03NGQ3ZDg2NWEwY2IucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDExOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAxMThUMjAxODU3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YmJiOWI2YzQzZjIzM2NkZDY0YWY3MmQzNDkwZmQ3Y2ExYjE1NDk4MWRkNzUxN2M0OGU0ZjdjM2Y2ZDc4MzdmYSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.XatzlsQZWCBfoZTudHl2ZtReL4ml72cq6IFSGicx7vc) Comments for the Questions, Answers, Wikis TagWikiExcerpts, TagWikis, ModerationNominations, WikiPlaceholders, PrivilegeWikis, AllPostTypes including deleted ones per month \(correlated by post\) \[[Wayback](https://web.archive.org/web/20260118201926/https://private-user-images.githubusercontent.com/2033367/537322714-a43a36be-4a30-421a-8235-74d7d865a0cb.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njg3Njc4MzcsIm5iZiI6MTc2ODc2NzUzNywicGF0aCI6Ii8yMDMzMzY3LzUzNzMyMjcxNC1hNDNhMzZiZS00YTMwLTQyMWEtODIzNS03NGQ3ZDg2NWEwY2IucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDExOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAxMThUMjAxODU3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YmJiOWI2YzQzZjIzM2NkZDY0YWY3MmQzNDkwZmQ3Y2ExYjE1NDk4MWRkNzUxN2M0OGU0ZjdjM2Y2ZDc4MzdmYSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.XatzlsQZWCBfoZTudHl2ZtReL4ml72cq6IFSGicx7vc)/[Archive](https://archive.is/2026.01.18-201925/https://private-user-images.githubusercontent.com/2033367/537322714-a43a36be-4a30-421a-8235-74d7d865a0cb.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njg3Njc4MzcsIm5iZiI6MTc2ODc2NzUzNywicGF0aCI6Ii8yMDMzMzY3LzUzNzMyMjcxNC1hNDNhMzZiZS00YTMwLTQyMWEtODIzNS03NGQ3ZDg2NWEwY2IucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDExOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAxMThUMjAxODU3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YmJiOWI2YzQzZjIzM2NkZDY0YWY3MmQzNDkwZmQ3Y2ExYjE1NDk4MWRkNzUxN2M0OGU0ZjdjM2Y2ZDc4MzdmYSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.XatzlsQZWCBfoZTudHl2ZtReL4ml72cq6IFSGicx7vc)\][537322714\-a43a36be\-4a30\-421a\-8235\-74d7d865a0cb\.png \(978×523\)](https://private-user-images.githubusercontent.com/2033367/537322714-a43a36be-4a30-421a-8235-74d7d865a0cb.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njg3Njc4MzcsIm5iZiI6MTc2ODc2NzUzNywicGF0aCI6Ii8yMDMzMzY3LzUzNzMyMjcxNC1hNDNhMzZiZS00YTMwLTQyMWEtODIzNS03NGQ3ZDg2NWEwY2IucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDExOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAxMThUMjAxODU3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YmJiOWI2YzQzZjIzM2NkZDY0YWY3MmQzNDkwZmQ3Y2ExYjE1NDk4MWRkNzUxN2M0OGU0ZjdjM2Y2ZDc4MzdmYSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.XatzlsQZWCBfoZTudHl2ZtReL4ml72cq6IFSGicx7vc) I wasn’t really sure what the best way was to add the count of comments \(which are in a different table\) into the results\. The above query correlates them on`PostId`\. This could also be done by`\[Month\]`\. Since they are correlated, part of the aggregation needs to be done in a separate query\. Initially I thought this could be done with an inner select \(officially called[subquery](https://en.wikipedia.org/wiki/Subquery)\), but didn’t get that to work quickly enough\. So I opted for using a WITH \(officially called[common table expressions](https://en.wikipedia.org/wiki/Hierarchical_and_recursive_queries_in_SQL#Common_table_expression)or CTE\)\. Since I hadn’t used SQL regularly for quite a while, I used these to get me going: 1. \[[WaybackFail](https://web.archive.org/web/20260119113130/https://www.google.com/search?q=sql+sum+inner+select+group+by)\][sql sum inner select group by – Google Search](https://www.google.com/search?q=sql+sum+inner+select+group+by) 2. \[[Wayback](https://web.archive.org/web/20260119105034/https://html.duckduckgo.com/html?q=sql+sum+inner+select+join+group+by)/[Archive](https://archive.is/2026.01.19-113055/https://html.duckduckgo.com/html?q=sql+sum+inner+select+join+group+by)\][sql sum inner select join group by at DuckDuckGo](https://html.duckduckgo.com/html?q=sql+sum+inner+select+join+group+by)which gave me this part of the above solution: 3. \[[Wayback](https://web.archive.org/web/20260119113351/https://stackoverflow.com/questions/23031118/trying-to-use-inner-join-and-group-by-sql-with-sum-function-not-working)/[Archive](https://archive.is/2026.01.19-113443/https://stackoverflow.com/questions/23031118/trying-to-use-inner-join-and-group-by-sql-with-sum-function-not-working)\][select – Trying to use INNER JOIN and GROUP BY SQL with SUM Function, Not Working – Stack Overflow](https://stackoverflow.com/questions/23031118/trying-to-use-inner-join-and-group-by-sql-with-sum-function-not-working)\(thanks \[[Wayback](https://web.archive.org/web/20260119120301/https://stackoverflow.com/users/3526836/rob4236)/[Archive](https://archive.is/2026.01.19-120401/https://stackoverflow.com/users/3526836/rob4236)\][Rob4236](https://stackoverflow.com/users/3526836/rob4236)and \[[Wayback](https://web.archive.org/web/20260119120305/https://stackoverflow.com/users/2704659/rory-ap)/[Archive](https://archive.is/2026.01.19-120314/https://stackoverflow.com/users/2704659/rory-ap)\][rory\.ap](https://stackoverflow.com/users/2704659/rory-ap)\) > #### Q `RES\_DATA`Contains my Customer as below ``` CUSTOMER ID | NAME 1, Robert 2, John 3, Peter ``` `INV\_DATA`Contains their INVOICES as Below ``` INVOICE ID | CUSTOMER ID | AMOUNT 100, 1, £49.95 200, 1, £105.95 300, 2, £400.00 400, 3, £150.00 500, 1, £25.00 ``` I am Trying to write a`SELECT`STATEMENT Which will give me the results as Below\. ``` CUSTOMER ID | NAME | TOTAL AMOUNT 1, Robert, £180.90 2, John, £400.00 3, Peter, £150.00 ``` #### A ``` SELECT a.[CUSTOMER ID], a.[NAME], SUM(b.[AMOUNT]) AS [TOTAL AMOUNT] FROM RES_DATA a INNER JOIN INV_DATA b ON a.[CUSTOMER ID]=b.[CUSTOMER ID] GROUP BY a.[CUSTOMER ID], a.[NAME] ``` 4. \[[Wayback](https://web.archive.org/web/20260119115854/https://html.duckduckgo.com/html?q=sql+sum+CTE+join+group+by)/[Archive](https://archive.is/2026.01.19-113619/https://html.duckduckgo.com/html?q=sql+sum+CTE+join+group+by)\][sql sum CTE join group by at DuckDuckGo](https://html.duckduckgo.com/html?q=sql+sum+CTE+join+group+by) 5. \[[Wayback](https://web.archive.org/web/20260119113624/https://stackoverflow.com/questions/53407330/using-group-by-inside-a-cte-for-aggregation)/[Archive](https://archive.is/2026.01.19-113608/https://stackoverflow.com/questions/53407330/using-group-by-inside-a-cte-for-aggregation)\][sql – Using GROUP BY Inside a CTE for Aggregation – Stack Overflow](https://stackoverflow.com/questions/53407330/using-group-by-inside-a-cte-for-aggregation)\(thanks \[[Wayback](https://web.archive.org/web/20260119113610/https://stackoverflow.com/users/8748459/leilanihagen)/[Archive](https://archive.is/2026.01.19-113611/https://stackoverflow.com/users/8748459/leilanihagen)\][leilanihagen](https://stackoverflow.com/users/8748459/leilanihagen)and \[[Wayback](https://web.archive.org/web/20260119113731/https://stackoverflow.com/users/3987784/sacse)/[Archive](https://archive.is/2026.01.19-113615/https://stackoverflow.com/users/3987784/sacse)\][sacse](https://stackoverflow.com/users/3987784/sacse)\) which confirmed a CTE solution works: > ``` WITH SumPerOrder (SalesOrderID, CalculatedSubTotalFromDetail) AS ( SELECT SalesOrderID ,SUM(LineTotal) FROM AdventureWorks2014.Sales.SalesOrderDetail GROUP BY SalesOrderID ) SELECT soh.SalesOrderID ,soh.SalesOrderNumber ,soh.SubTotal AS OriginalSubTotal ,spo.CalculatedSubTotalFromDetail ,(soh.SubTotal - spo.CalculatedSubTotalFromDetail) AS Difference FROM AdventureWorks2014.Sales.SalesOrderHeader soh INNER JOIN SumPerOrder spo ON soh.SalesOrderID = spo.SalesOrderID ``` 6. \[[Wayback](https://web.archive.org/web/20260119113839/https://old.reddit.com/r/SQL/comments/16p2f0e/sum_colums_in_one_table_and_join_with_another/)/[Archive](https://archive.is/2026.01.19-113825/https://old.reddit.com/r/SQL/comments/16p2f0e/sum_colums_in_one_table_and_join_with_another/)\][Sum colums in one table and join with another table : SQL](https://old.reddit.com/r/SQL/comments/16p2f0e/sum_colums_in_one_table_and_join_with_another/)was referenced from the first query and shows the same solution as the prior link: > ``` WITH sums AS ( SELECT consignmentid , SUM(quantity) AS sum_qty FROM consignmentitemstbl GROUP BY consignmentid ) SELECT c.consignmentid , c.[total volume] , c.[total weight] , COALESCE(sums.sum_qty,0) AS [total quantity] FROM consignmentstbl AS c LEFT OUTER JOIN sums ON sums.consignmentid = c.consignmentid ``` ### Combined graph adding comments to all post types This took me a few tries as the first try failed with “`Line 25: Invalid column name 'Month'\.`“: > ``` WITH PostCommentCounts AS ( SELECT DATEFROMPARTS(YEAR(Comments.CreationDate), MONTH(Comments.CreationDate), 1) AS [Month], COUNT(Id) AS CommentIdCount FROM Comments GROUP BY DATEFROMPARTS(YEAR(Comments.CreationDate), MONTH(Comments.CreationDate), 1) ) SELECT DATEFROMPARTS(YEAR(PostsWithDeleted.CreationDate), MONTH(PostsWithDeleted.CreationDate), 1) AS [Month], SUM(CASE WHEN PostTypeId = 1 THEN 1 ELSE 0 END) AS [Questions], SUM(CASE WHEN PostTypeId = 2 THEN 1 ELSE 0 END) AS [Answers], SUM(CASE WHEN PostTypeId = 3 THEN 1 ELSE 0 END) AS [Wikis], SUM(CASE WHEN PostTypeId = 4 THEN 1 ELSE 0 END) AS [TagWikiExcerpts], SUM(CASE WHEN PostTypeId = 5 THEN 1 ELSE 0 END) AS [TagWikis], SUM(CASE WHEN PostTypeId = 6 THEN 1 ELSE 0 END) AS [ModeratorNominations], SUM(CASE WHEN PostTypeId = 7 THEN 1 ELSE 0 END) AS [WikiPlaceholders], SUM(CASE WHEN PostTypeId = 8 THEN 1 ELSE 0 END) AS [PrivilegeWikis], SUM(PostCommentCounts.CommentIdCount) AS [Comments], COUNT(PostsWithDeleted.Id) AS [AllPostTypes] FROM PostsWithDeleted LEFT JOIN PostCommentCounts ON PostCommentCounts.[Month] = PostsWithDeleted.[Month] GROUP BY DATEFROMPARTS(YEAR(PostsWithDeleted.CreationDate), MONTH(PostsWithDeleted.CreationDate), 1) ORDER BY [Month] ASC ``` That happened to be the`PostsWithDeleted\.\[Month\]`bit\. A new try failed as well, but with a “`Line 1: Arithmetic overflow error converting expression to data type int\.`“: > ``` WITH PostCommentCounts AS ( SELECT DATEFROMPARTS(YEAR(Comments.CreationDate), MONTH(Comments.CreationDate), 1) AS [Month], COUNT(Id) AS CommentIdCount FROM Comments GROUP BY DATEFROMPARTS(YEAR(Comments.CreationDate), MONTH(Comments.CreationDate), 1) ) SELECT DATEFROMPARTS(YEAR(PostsWithDeleted.CreationDate), MONTH(PostsWithDeleted.CreationDate), 1) AS [Month], SUM(CASE WHEN PostTypeId = 1 THEN 1 ELSE 0 END) AS [Questions], SUM(CASE WHEN PostTypeId = 2 THEN 1 ELSE 0 END) AS [Answers], SUM(CASE WHEN PostTypeId = 3 THEN 1 ELSE 0 END) AS [Wikis], SUM(CASE WHEN PostTypeId = 4 THEN 1 ELSE 0 END) AS [TagWikiExcerpts], SUM(CASE WHEN PostTypeId = 5 THEN 1 ELSE 0 END) AS [TagWikis], SUM(CASE WHEN PostTypeId = 6 THEN 1 ELSE 0 END) AS [ModeratorNominations], SUM(CASE WHEN PostTypeId = 7 THEN 1 ELSE 0 END) AS [WikiPlaceholders], SUM(CASE WHEN PostTypeId = 8 THEN 1 ELSE 0 END) AS [PrivilegeWikis], SUM(PostCommentCounts.CommentIdCount) AS [Comments], COUNT(PostsWithDeleted.Id) AS [AllPostTypes] FROM PostsWithDeleted LEFT JOIN PostCommentCounts ON PostCommentCounts.[Month] = DATEFROMPARTS(YEAR(PostsWithDeleted.CreationDate), MONTH(PostsWithDeleted.CreationDate), 1) GROUP BY DATEFROMPARTS(YEAR(PostsWithDeleted.CreationDate), MONTH(PostsWithDeleted.CreationDate), 1) ORDER BY [Month] ASC ``` That I could not pinpoint when reading the error message \(as it indicated “Line 1”\), but my gut feeling was either of these: 1. the query inside`PostCommentCounts`CTE at the start with the most likely place the`DATEFROMPARTS` 2. the`SUM`at “Line 12” which was confirmed by a quick search where I learned`COUNT\_BIG`exists, but`SUM\_BIG`does not\. Thinking about that twice that made sense:`COUNT\_BIG`is about counting so there cannot be a cast inside the`COUNT`expression, but`SUM`is about summing the inside of the expression and that’s where a`CAST`needs to take place\. The learning: 1. \[[Wayback](https://web.archive.org/web/20260122110010/https://html.duckduckgo.com/html?q=Line+1%3A+Arithmetic+overflow+error+converting+expression+to+data+type+int.)/[Archive](https://archive.is/2026.01.22-111232/https://html.duckduckgo.com/html?q=Line+1:+Arithmetic+overflow+error+converting+expression+to+data+type+int.)\][Line 1: Arithmetic overflow error converting expression to data type int\. at DuckDuckGo](https://html.duckduckgo.com/html?q=Line+1:+Arithmetic+overflow+error+converting+expression+to+data+type+int.) 2. \[[Wayback](https://web.archive.org/web/20260122111300/https://stackoverflow.com/questions/15950580/sql-server-arithmetic-overflow-error-converting-expression-to-data-type-int)/[Archive](https://archive.is/2026.01.22-111644/https://stackoverflow.com/questions/15950580/sql-server-arithmetic-overflow-error-converting-expression-to-data-type-int)\][SQL Server : Arithmetic overflow error converting expression to data type int – Stack Overflow](https://stackoverflow.com/questions/15950580/sql-server-arithmetic-overflow-error-converting-expression-to-data-type-int)\(thanks \[[Wayback](https://web.archive.org/web/20260122110723/https://stackoverflow.com/users/2270544/user2270544)/[Archive](https://archive.is/2026.01.22-111549/https://stackoverflow.com/users/2270544/user2270544)\][user2270544 – Stack Overflow](https://stackoverflow.com/users/2270544/user2270544), \[[Wayback](https://web.archive.org/web/20260122110737/https://stackoverflow.com/users/1494397/jeff-johnston)/[Archive](https://archive.is/2026.01.22-111243/https://stackoverflow.com/users/1494397/jeff-johnston)\][Jeff Johnston](https://stackoverflow.com/users/1494397/jeff-johnston)and \[[Wayback](https://web.archive.org/web/20260122111146/https://stackoverflow.com/users/8442097/john-g)/[Archive](https://archive.is/2026.01.22-111244/https://stackoverflow.com/users/8442097/john-g)\][John G](https://stackoverflow.com/users/8442097/john-g)\) > #### A Is the problem with`SUM\(billableDuration\)`? To find out, try commenting out that line and see if it works\. It could be that the sum is exceeding the maximum`int`\. If so, try replacing it with`SUM\(CAST\(billableDuration AS BIGINT\)\)`\. #### A Very simple: Use ``` COUNT_BIG(*) AS NumStreams ``` 3. \[[Wayback](https://web.archive.org/web/20260122111401/https://html.duckduckgo.com/html?q=COUNT_BIG)/[Archive](https://archive.is/2026.01.22-111306/https://html.duckduckgo.com/html?q=COUNT_BIG)\][COUNT\_BIG at DuckDuckGo](https://html.duckduckgo.com/html?q=COUNT_BIG) 4. \[[Wayback](https://web.archive.org/web/20260122110831/https://learn.microsoft.com/en-us/sql/t-sql/functions/count-big-transact-sql?view=sql-server-ver17)/[Archive](https://archive.is/2026.01.22-111019/https://learn.microsoft.com/en-us/sql/t-sql/functions/count-big-transact-sql?view=sql-server-ver17)\][`COUNT\_BIG`\(Transact\-SQL\) – SQL Server \| Microsoft Learn](https://learn.microsoft.com/en-us/sql/t-sql/functions/count-big-transact-sql?view=sql-server-ver17) 5. \[[Wayback](https://web.archive.org/web/20260122112024/https://database.guide/count-vs-count_big-in-sql-server-whats-the-difference/)/[Archive](https://archive.is/2026.01.22-111929/https://database.guide/count-vs-count_big-in-sql-server-whats-the-difference/)\][`COUNT\(\)`vs`COUNT\_BIG\(\)`in SQL Server: What’s the Difference?](https://database.guide/count-vs-count_big-in-sql-server-whats-the-difference/) > … The difference is that`COUNT\(\)`returns its result as an**int**, whereas`COUNT\_BIG\(\)`returns its result as a**bigint**\. In other words, you’ll need to use`COUNT\_BIG\(\)`if you expect its results to be larger than 2,147,483,647 \(i\.e\. if the query returns more than 2,147,483,647 rows\)\. … We can use the`sp\_describe\_first\_result\_set`stored procedure to check the return data type each of these functions\. ### Check the Data Type for COUNT\(\) ``` EXEC sp_describe_first_result_set N'SELECT COUNT(*) FROM Fact.[Order]', null, 0; ``` Result \(using vertical output\): ``` is_hidden | 0 column_ordinal | 1 name | NULL is_nullable | 1 system_type_id | 56 system_type_name | int max_length | 4 precision | 10 scale | 0 … ``` … ### Check the Data Type for COUNT\_BIG\(\) For this example, all we need to do is replace`COUNT\(\*\)`with`COUNT\_BIG\(\*\)`: ``` EXEC sp_describe_first_result_set N'SELECT COUNT_BIG(*) FROM Fact.[Order]', null, 0; ``` Result \(using vertical output\): ``` is_hidden | 0 column_ordinal | 1 name | NULL is_nullable | 1 system_type_id | 127 system_type_name | bigint max_length | 8 precision | 19 scale | 0 … ``` … By the way, a quicker way of doing the above is to combine both functions into query when calling the stored procedure\. Like this: ``` EXEC sp_describe_first_result_set N'SELECT COUNT(*), COUNT_BIG(*) FROM Fact.[Order]', null, 0; ``` That taught me about a I think I knew would exist, but not its name: 6. \[[Wayback](https://web.archive.org/web/20260122145146/https://html.duckduckgo.com/html?q=sp_describe_first_result_set)/[Archive](https://archive.is/2026.01.22-154527/https://html.duckduckgo.com/html?q=sp_describe_first_result_set)\][sp\_describe\_first\_result\_set at DuckDuckGo](https://html.duckduckgo.com/html?q=sp_describe_first_result_set) 7. \[[Wayback](https://web.archive.org/web/20260122145104/https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-describe-first-result-set-transact-sql?view=sql-server-ver17)/[Archive](https://archive.is/2026.01.22-150318/https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-describe-first-result-set-transact-sql?view=sql-server-ver17)\][`sp\_describe\_first\_result\_set`\(Transact\-SQL\) – SQL Server \| Microsoft Learn](https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-describe-first-result-set-transact-sql?view=sql-server-ver17) > Returns the metadata for the first possible result set of the Transact\-SQL batch\. Returns an empty result set if the batch returns no results\. Raises an error if the Database Engine can’t determine the metadata for the first query that will be executed by performing a static analysis\. So I tried casting which failed with a much more specific location – “`Line 3: Explicit conversion from data type date to bigint is not allowed\.`” indicating modifying the CTE wasn’t the solution: > ``` WITH PostCommentCounts AS ( SELECT CAST(DATEFROMPARTS(YEAR(Comments.CreationDate), MONTH(Comments.CreationDate), 1) AS BIGINT) AS [MonthBIGINT], COUNT(Id) AS CommentIdCount FROM Comments GROUP BY DATEFROMPARTS(YEAR(Comments.CreationDate), MONTH(Comments.CreationDate), 1) ) SELECT DATEFROMPARTS(YEAR(PostsWithDeleted.CreationDate), MONTH(PostsWithDeleted.CreationDate), 1) AS [Month], SUM(CASE WHEN PostTypeId = 1 THEN 1 ELSE 0 END) AS [Questions], SUM(CASE WHEN PostTypeId = 2 THEN 1 ELSE 0 END) AS [Answers], SUM(CASE WHEN PostTypeId = 3 THEN 1 ELSE 0 END) AS [Wikis], SUM(CASE WHEN PostTypeId = 4 THEN 1 ELSE 0 END) AS [TagWikiExcerpts], SUM(CASE WHEN PostTypeId = 5 THEN 1 ELSE 0 END) AS [TagWikis], SUM(CASE WHEN PostTypeId = 6 THEN 1 ELSE 0 END) AS [ModeratorNominations], SUM(CASE WHEN PostTypeId = 7 THEN 1 ELSE 0 END) AS [WikiPlaceholders], SUM(CASE WHEN PostTypeId = 8 THEN 1 ELSE 0 END) AS [PrivilegeWikis], SUM(PostCommentCounts.CommentIdCount) AS [Comments], COUNT(PostsWithDeleted.Id) AS [AllPostTypes] FROM PostsWithDeleted LEFT JOIN PostCommentCounts ON PostCommentCounts.[MonthBIGINT] = CAST(DATEFROMPARTS(YEAR(PostsWithDeleted.CreationDate), MONTH(PostsWithDeleted.CreationDate), 1) AS BIGINT) GROUP BY DATEFROMPARTS(YEAR(PostsWithDeleted.CreationDate), MONTH(PostsWithDeleted.CreationDate), 1) ORDER BY [Month] ASC ``` to split the grouping into`\[Year\]`and`\[Month\]`portions, then and cast the`SUM`parameter to use`BIGINT`: > ``` WITH PostCommentCounts AS ( SELECT YEAR(Comments.CreationDate) AS [Year], MONTH(Comments.CreationDate) AS [Month], COUNT(Id) AS CommentIdCount FROM Comments GROUP BY YEAR(Comments.CreationDate), MONTH(Comments.CreationDate) ) SELECT DATEFROMPARTS(YEAR(PostsWithDeleted.CreationDate), MONTH(PostsWithDeleted.CreationDate), 1) AS [Month], SUM(CASE WHEN PostTypeId = 1 THEN 1 ELSE 0 END) AS [Questions], SUM(CASE WHEN PostTypeId = 2 THEN 1 ELSE 0 END) AS [Answers], SUM(CASE WHEN PostTypeId = 3 THEN 1 ELSE 0 END) AS [Wikis], SUM(CASE WHEN PostTypeId = 4 THEN 1 ELSE 0 END) AS [TagWikiExcerpts], SUM(CASE WHEN PostTypeId = 5 THEN 1 ELSE 0 END) AS [TagWikis], SUM(CASE WHEN PostTypeId = 6 THEN 1 ELSE 0 END) AS [ModeratorNominations], SUM(CASE WHEN PostTypeId = 7 THEN 1 ELSE 0 END) AS [WikiPlaceholders], SUM(CASE WHEN PostTypeId = 8 THEN 1 ELSE 0 END) AS [PrivilegeWikis], SUM(CAST(PostCommentCounts.CommentIdCount AS BIGINT)) AS [Comments], COUNT(PostsWithDeleted.Id) AS [AllPostTypes] FROM PostsWithDeleted LEFT JOIN PostCommentCounts ON PostCommentCounts.[Year] = YEAR(PostsWithDeleted.CreationDate) AND PostCommentCounts.[Month] = MONTH(PostsWithDeleted.CreationDate) GROUP BY DATEFROMPARTS(YEAR(PostsWithDeleted.CreationDate), MONTH(PostsWithDeleted.CreationDate), 1) ORDER BY [Month] ASC ``` The resulting graph \(and to a lesser extend the 7 second query duration\) then made me slap my head: I should have used`INNER JOIN`instead of`LEFT JOIN`,which is short for`LEFT OUTER JOIN`, explaining the explosion of the count of Comments: > ![Explosion of Comments values (not rows) because of the LEFT JOIN](https://web.archive.org/web/20260119181700if_/https://private-user-images.githubusercontent.com/2033367/537711393-9eeb1895-2536-434c-9274-ff0ea6245ce9.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njg4NDY4OTEsIm5iZiI6MTc2ODg0NjU5MSwicGF0aCI6Ii8yMDMzMzY3LzUzNzcxMTM5My05ZWViMTg5NS0yNTM2LTQzNGMtOTI3NC1mZjBlYTYyNDVjZTkucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDExOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAxMTlUMTgxNjMxWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NzA2MzBkODBmM2YxY2VjNTQwMDJhNzU4YTE5Y2VkYjllMjJlZjUzOTFhZDhmZDcyYzFmM2ZmNTYzNDkzNzFkZSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.FVVbROOMWSdEycj2F7p0MT7qo21JoOe9DdPTOGnXol8) Explosion of Comments values \(not rows\) because of the LEFT JOIN \[[Wayback](https://web.archive.org/web/20260119181700/https://private-user-images.githubusercontent.com/2033367/537711393-9eeb1895-2536-434c-9274-ff0ea6245ce9.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njg4NDY4OTEsIm5iZiI6MTc2ODg0NjU5MSwicGF0aCI6Ii8yMDMzMzY3LzUzNzcxMTM5My05ZWViMTg5NS0yNTM2LTQzNGMtOTI3NC1mZjBlYTYyNDVjZTkucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDExOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAxMTlUMTgxNjMxWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NzA2MzBkODBmM2YxY2VjNTQwMDJhNzU4YTE5Y2VkYjllMjJlZjUzOTFhZDhmZDcyYzFmM2ZmNTYzNDkzNzFkZSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.FVVbROOMWSdEycj2F7p0MT7qo21JoOe9DdPTOGnXol8)/[Archive](https://archive.is/2026.01.19-181654/https://private-user-images.githubusercontent.com/2033367/537711393-9eeb1895-2536-434c-9274-ff0ea6245ce9.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njg4NDY4OTEsIm5iZiI6MTc2ODg0NjU5MSwicGF0aCI6Ii8yMDMzMzY3LzUzNzcxMTM5My05ZWViMTg5NS0yNTM2LTQzNGMtOTI3NC1mZjBlYTYyNDVjZTkucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDExOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAxMTlUMTgxNjMxWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NzA2MzBkODBmM2YxY2VjNTQwMDJhNzU4YTE5Y2VkYjllMjJlZjUzOTFhZDhmZDcyYzFmM2ZmNTYzNDkzNzFkZSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.FVVbROOMWSdEycj2F7p0MT7qo21JoOe9DdPTOGnXol8)\][537711393\-9eeb1895\-2536\-434c\-9274\-ff0ea6245ce9\.png \(979×523\)](https://private-user-images.githubusercontent.com/2033367/537711393-9eeb1895-2536-434c-9274-ff0ea6245ce9.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njg4NDY4OTEsIm5iZiI6MTc2ODg0NjU5MSwicGF0aCI6Ii8yMDMzMzY3LzUzNzcxMTM5My05ZWViMTg5NS0yNTM2LTQzNGMtOTI3NC1mZjBlYTYyNDVjZTkucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDExOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAxMTlUMTgxNjMxWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NzA2MzBkODBmM2YxY2VjNTQwMDJhNzU4YTE5Y2VkYjllMjJlZjUzOTFhZDhmZDcyYzFmM2ZmNTYzNDkzNzFkZSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.FVVbROOMWSdEycj2F7p0MT7qo21JoOe9DdPTOGnXol8) This meant I could try to go back to the first query, the one resulting in “`Line 1: Arithmetic overflow error converting expression to data type int\.`“, and replace the`LEFT JOIN`with`INNER JOIN`: > ``` WITH PostCommentCounts AS ( SELECT DATEFROMPARTS(YEAR(Comments.CreationDate), MONTH(Comments.CreationDate), 1) AS [Month], COUNT(Id) AS CommentIdCount FROM Comments GROUP BY DATEFROMPARTS(YEAR(Comments.CreationDate), MONTH(Comments.CreationDate), 1) ) SELECT DATEFROMPARTS(YEAR(PostsWithDeleted.CreationDate), MONTH(PostsWithDeleted.CreationDate), 1) AS [Month], SUM(CASE WHEN PostTypeId = 1 THEN 1 ELSE 0 END) AS [Questions], SUM(CASE WHEN PostTypeId = 2 THEN 1 ELSE 0 END) AS [Answers], SUM(CASE WHEN PostTypeId = 3 THEN 1 ELSE 0 END) AS [Wikis], SUM(CASE WHEN PostTypeId = 4 THEN 1 ELSE 0 END) AS [TagWikiExcerpts], SUM(CASE WHEN PostTypeId = 5 THEN 1 ELSE 0 END) AS [TagWikis], SUM(CASE WHEN PostTypeId = 6 THEN 1 ELSE 0 END) AS [ModeratorNominations], SUM(CASE WHEN PostTypeId = 7 THEN 1 ELSE 0 END) AS [WikiPlaceholders], SUM(CASE WHEN PostTypeId = 8 THEN 1 ELSE 0 END) AS [PrivilegeWikis], SUM(CAST(PostCommentCounts.CommentIdCount AS BIGINT)) AS [Comments], COUNT(PostCommentCounts.CommentIdCount) AS [PostCommentCountsCount], COUNT(PostsWithDeleted.Id) AS [AllPostTypes] FROM PostsWithDeleted INNER JOIN PostCommentCounts ON PostCommentCounts.[Month] = DATEFROMPARTS(YEAR(PostsWithDeleted.CreationDate), MONTH(PostsWithDeleted.CreationDate), 1) GROUP BY DATEFROMPARTS(YEAR(PostsWithDeleted.CreationDate), MONTH(PostsWithDeleted.CreationDate), 1) ORDER BY [Month] ASC ``` But the resulting graph also returned way too high values for Comments: > ![INNER JOIN also has way too high values for Comments.](https://web.archive.org/web/20260119194835if_/https://private-user-images.githubusercontent.com/2033367/537733862-c2f47291-107b-42fe-94ca-a3f53a2a88e3.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njg4NTIzODksIm5iZiI6MTc2ODg1MjA4OSwicGF0aCI6Ii8yMDMzMzY3LzUzNzczMzg2Mi1jMmY0NzI5MS0xMDdiLTQyZmUtOTRjYS1hM2Y1M2EyYTg4ZTMucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDExOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAxMTlUMTk0ODA5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZjRhOGY2ZjM5NDBiMDM4NmM5ZDVmYzYwMTI1MDhkMGMxNDM3YjcyZWZmNDhjNTdlZDgzOWNmNWZlNjY3Yjc0ZCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.KVwX-gfcXxBg9DhFLoAfF6gbkVhSMyADZSimkKQU3bg) INNER JOIN also has way too high values for Comments\. \[[Wayback](https://web.archive.org/web/20260119194835/https://private-user-images.githubusercontent.com/2033367/537733862-c2f47291-107b-42fe-94ca-a3f53a2a88e3.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njg4NTIzODksIm5iZiI6MTc2ODg1MjA4OSwicGF0aCI6Ii8yMDMzMzY3LzUzNzczMzg2Mi1jMmY0NzI5MS0xMDdiLTQyZmUtOTRjYS1hM2Y1M2EyYTg4ZTMucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDExOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAxMTlUMTk0ODA5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZjRhOGY2ZjM5NDBiMDM4NmM5ZDVmYzYwMTI1MDhkMGMxNDM3YjcyZWZmNDhjNTdlZDgzOWNmNWZlNjY3Yjc0ZCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.KVwX-gfcXxBg9DhFLoAfF6gbkVhSMyADZSimkKQU3bg)/[Archive](https://archive.is/2026.01.19-194836/https://private-user-images.githubusercontent.com/2033367/537733862-c2f47291-107b-42fe-94ca-a3f53a2a88e3.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njg4NTIzODksIm5iZiI6MTc2ODg1MjA4OSwicGF0aCI6Ii8yMDMzMzY3LzUzNzczMzg2Mi1jMmY0NzI5MS0xMDdiLTQyZmUtOTRjYS1hM2Y1M2EyYTg4ZTMucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDExOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAxMTlUMTk0ODA5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZjRhOGY2ZjM5NDBiMDM4NmM5ZDVmYzYwMTI1MDhkMGMxNDM3YjcyZWZmNDhjNTdlZDgzOWNmNWZlNjY3Yjc0ZCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.KVwX-gfcXxBg9DhFLoAfF6gbkVhSMyADZSimkKQU3bg)\][537733862\-c2f47291\-107b\-42fe\-94ca\-a3f53a2a88e3\.png \(980×495\)](https://private-user-images.githubusercontent.com/2033367/537733862-c2f47291-107b-42fe-94ca-a3f53a2a88e3.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njg4NTIzODksIm5iZiI6MTc2ODg1MjA4OSwicGF0aCI6Ii8yMDMzMzY3LzUzNzczMzg2Mi1jMmY0NzI5MS0xMDdiLTQyZmUtOTRjYS1hM2Y1M2EyYTg4ZTMucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDExOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAxMTlUMTk0ODA5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZjRhOGY2ZjM5NDBiMDM4NmM5ZDVmYzYwMTI1MDhkMGMxNDM3YjcyZWZmNDhjNTdlZDgzOWNmNWZlNjY3Yjc0ZCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.KVwX-gfcXxBg9DhFLoAfF6gbkVhSMyADZSimkKQU3bg) #### Back to the drawing board My next try was to use a SUM on a subquery, but that failed with a “`Line 22: Incorrect syntax near the keyword 'SELECT'\. Incorrect syntax near '\)'\.`“: > ``` WITH PostCommentCounts AS ( SELECT DATEFROMPARTS(YEAR(Comments.CreationDate), MONTH(Comments.CreationDate), 1) AS [Month], COUNT(Id) AS CommentIdCount FROM Comments GROUP BY DATEFROMPARTS(YEAR(Comments.CreationDate), MONTH(Comments.CreationDate), 1) ) SELECT DATEFROMPARTS(YEAR(PostsWithDeleted.CreationDate), MONTH(PostsWithDeleted.CreationDate), 1) AS [Month], SUM(CASE WHEN PostTypeId = 1 THEN 1 ELSE 0 END) AS [Questions], SUM(CASE WHEN PostTypeId = 2 THEN 1 ELSE 0 END) AS [Answers], SUM(CASE WHEN PostTypeId = 3 THEN 1 ELSE 0 END) AS [Wikis], SUM(CASE WHEN PostTypeId = 4 THEN 1 ELSE 0 END) AS [TagWikiExcerpts], SUM(CASE WHEN PostTypeId = 5 THEN 1 ELSE 0 END) AS [TagWikis], SUM(CASE WHEN PostTypeId = 6 THEN 1 ELSE 0 END) AS [ModeratorNominations], SUM(CASE WHEN PostTypeId = 7 THEN 1 ELSE 0 END) AS [WikiPlaceholders], SUM(CASE WHEN PostTypeId = 8 THEN 1 ELSE 0 END) AS [PrivilegeWikis], SUM ( SELECT PostCommentCounts.CommentIdCount FROM PostCommentCounts WHERE PostCommentCounts.[Month] = PostsWithDeleted.[Month] ) AS [Comments], COUNT(PostsWithDeleted.Id) AS [AllPostTypes] FROM PostsWithDeleted GROUP BY DATEFROMPARTS(YEAR(PostsWithDeleted.CreationDate), MONTH(PostsWithDeleted.CreationDate), 1) ORDER BY [Month] ASC ``` Back then, I confused the order of`SUM`and`SELECT,`*and*I didn’t understand the`'\)'`part of that error, but did some digging: - \[[Wayback](https://web.archive.org/web/20260121132653/https://html.duckduckgo.com/html?q=sql+server+subquery+inside+sum)/[Archive](https://archive.is/2026.01.21-132612/https://html.duckduckgo.com/html?q=sql+server+subquery+inside+sum)\][sql server subquery inside sum at DuckDuckGo](https://html.duckduckgo.com/html?q=sql+server+subquery+inside+sum)\(because SEDE is based on SQL Azure, which is based on SQL Server\) - \[[Wayback](https://web.archive.org/web/20260121141611/https://html.duckduckgo.com/html?q=%22sql%22+%22subquery%22+inside+%22sum%22)/[Archive](https://archive.is/2026.01.21-142353/https://html.duckduckgo.com/html?q=%22sql%22+%22subquery%22+inside+%22sum%22)\][“sql” “subquery” inside “sum” at DuckDuckGo](https://html.duckduckgo.com/html?q=%22sql%22+%22subquery%22+inside+%22sum%22)\(going more generic as the above query didn’t get useful results\) - \[[Wayback](https://web.archive.org/web/20260121132704/https://stackoverflow.com/questions/63394415/why-sql-subquery-doesnt-work-inside-sum-function)/[Archive](https://archive.is/2026.01.21-132736/https://stackoverflow.com/questions/63394415/why-sql-subquery-doesnt-work-inside-sum-function)\][Why SQL subquery doesn’t work inside SUM function? – Stack Overflow](https://stackoverflow.com/questions/63394415/why-sql-subquery-doesnt-work-inside-sum-function)\(thanks \[[Wayback](https://web.archive.org/web/20260121132611/https://stackoverflow.com/users/14099114/trinh-cuong)/[Archive](https://archive.is/2026.01.21-132930/https://stackoverflow.com/users/14099114/trinh-cuong)\][Trinh Cuong](https://stackoverflow.com/users/14099114/trinh-cuong), \[[Wayback](https://web.archive.org/web/20260121132551/https://stackoverflow.com/users/2270762/thorsten-kettner)/[Archive](https://archive.is/2026.01.21-132604/https://stackoverflow.com/users/2270762/thorsten-kettner)\][Thorsten Kettner](https://stackoverflow.com/users/2270762/thorsten-kettner)and \[[Wayback](https://web.archive.org/web/20260121132649/https://stackoverflow.com/users/1144035/gordon-linoff)/[Archive](https://archive.is/2026.01.21-132902/https://stackoverflow.com/users/1144035/gordon-linoff)\][Gordon Linoff](https://stackoverflow.com/users/1144035/gordon-linoff)\) > #### Q I’m learning SQL, and the lesson is subquery\. My query is: ``` select sum (select tientra from thang7_8714 where tientra > 0) as tmp; ``` But Postgres notice me the message: ``` ERROR: syntax error at or near "select" LINE 1: select sum (select tientra from thang7_8714 where tientra > ... SQL state: 42601 Character: 13 ``` #### A ##### SUM with a subquery `SUM`**wants one parameter\. This can be a fixed value \(e\.g\. 123\) or a column \(e\.g\. mycolumn\) or an expression \(e\.g\. 123 \* mycolumn\) or a subquery\. But this subquery would have to be scalar, which means it returns only one value\.** A subquery is surrounded by parentheses, so such`SUM`with a subquery would look like this: ``` select sum( (select t2.value from t2 where t2.id = t1.id_t1) ) from t1; ``` But subqueries inside aggregate functions are extremely rare, because we can achieve the same with a join \(e\.g\.`select sum\(t2\.value\) from t1 join t2 on t2\.id = t1\.id\_t2;`\)\. ##### Typical places for subqueries: … that answer finished with a list \(including examples\) of places where subqueries usually are used, and was followed by this answer: > #### A In general, SQL does not allow aggregation functions to have arguments that are subqueries\. The generic solution is to move the aggregation*inside*the subquery: ``` select (select sum(tientra) from thang7_8714 where tientra > 0) as tmp; ``` Presumably, you know that the more canonical method for solving this is: ``` select sum(tientra) as tmp from thang7_8714 where tientra > 0; ``` This shows: 1. that[PostgreSQL](https://en.wikipedia.org/wiki/PostgreSQL)has a better error message than the SEDE \(which is based on[SQL Azure](https://en.wikipedia.org/wiki/SQL_Azure), which simplified is the a very recent[SQL Server](https://en.wikipedia.org/wiki/SQL_Server)version running on[Microsoft Azure](https://en.wikipedia.org/wiki/Microsoft_Azure)\) 2. the conditions an aggregate expression needs to meet 3. an alternative In retrospect, it is obviously why a`SUM`needs a single value in its expression: it will aggregate \(in this case summate\) the single value for each occurance in the current`GROUP BY`\. Even adding an extra set of parenthesis as suggested in the above answer does not resolve the “single value” problem: it just returns either a less specific answer “`Something unexpected went wrong while running your query\.`” or “`Line 25: Cannot perform an aggregate function on an expression containing an aggregate or a subquery\.`“: > ``` WITH PostCommentCounts AS ( SELECT DATEFROMPARTS(YEAR(Comments.CreationDate), MONTH(Comments.CreationDate), 1) AS [Month], COUNT(Id) AS CommentIdCount FROM Comments GROUP BY DATEFROMPARTS(YEAR(Comments.CreationDate), MONTH(Comments.CreationDate), 1) ) SELECT DATEFROMPARTS(YEAR(PostsWithDeleted.CreationDate), MONTH(PostsWithDeleted.CreationDate), 1) AS [Month], SUM(CASE WHEN PostTypeId = 1 THEN 1 ELSE 0 END) AS [Questions], SUM(CASE WHEN PostTypeId = 2 THEN 1 ELSE 0 END) AS [Answers], SUM(CASE WHEN PostTypeId = 3 THEN 1 ELSE 0 END) AS [Wikis], SUM(CASE WHEN PostTypeId = 4 THEN 1 ELSE 0 END) AS [TagWikiExcerpts], SUM(CASE WHEN PostTypeId = 5 THEN 1 ELSE 0 END) AS [TagWikis], SUM(CASE WHEN PostTypeId = 6 THEN 1 ELSE 0 END) AS [ModeratorNominations], SUM(CASE WHEN PostTypeId = 7 THEN 1 ELSE 0 END) AS [WikiPlaceholders], SUM(CASE WHEN PostTypeId = 8 THEN 1 ELSE 0 END) AS [PrivilegeWikis], SUM (( SELECT PostCommentCounts.CommentIdCount FROM PostCommentCounts WHERE PostCommentCounts.[Month] = PostsWithDeleted.[Month] )) AS [Comments], COUNT(PostsWithDeleted.Id) AS [AllPostTypes] FROM PostsWithDeleted GROUP BY DATEFROMPARTS(YEAR(PostsWithDeleted.CreationDate), MONTH(PostsWithDeleted.CreationDate), 1) ORDER BY [Month] ASC ``` That means the`SUM`needs to be inside the`SELECT`, so I basically swapped the`SUM`and`SELECT`parts of it and this worked \(In addition, as aliases apparently of the superquery are not allowed in the subquery causing the ambiguous error message “`Line 23: Invalid column name 'Month'\.`“, I needed to replace`PostsWithDeleted\.\[Month\]`with`DATEFROMPARTS\(YEAR\(PostsWithDeleted\.CreationDate\), MONTH\(PostsWithDeleted\.CreationDate\), 1\)`: > ``` WITH PostCommentCounts AS ( SELECT DATEFROMPARTS(YEAR(Comments.CreationDate), MONTH(Comments.CreationDate), 1) AS [Month], COUNT(Id) AS CommentIdCount FROM Comments GROUP BY DATEFROMPARTS(YEAR(Comments.CreationDate), MONTH(Comments.CreationDate), 1) ) SELECT DATEFROMPARTS(YEAR(PostsWithDeleted.CreationDate), MONTH(PostsWithDeleted.CreationDate), 1) AS [Month], SUM(CASE WHEN PostTypeId = 1 THEN 1 ELSE 0 END) AS [Questions], SUM(CASE WHEN PostTypeId = 2 THEN 1 ELSE 0 END) AS [Answers], SUM(CASE WHEN PostTypeId = 3 THEN 1 ELSE 0 END) AS [Wikis], SUM(CASE WHEN PostTypeId = 4 THEN 1 ELSE 0 END) AS [TagWikiExcerpts], SUM(CASE WHEN PostTypeId = 5 THEN 1 ELSE 0 END) AS [TagWikis], SUM(CASE WHEN PostTypeId = 6 THEN 1 ELSE 0 END) AS [ModeratorNominations], SUM(CASE WHEN PostTypeId = 7 THEN 1 ELSE 0 END) AS [WikiPlaceholders], SUM(CASE WHEN PostTypeId = 8 THEN 1 ELSE 0 END) AS [PrivilegeWikis], ( SELECT SUM(PostCommentCounts.CommentIdCount) FROM PostCommentCounts WHERE PostCommentCounts.[Month] = DATEFROMPARTS(YEAR(PostsWithDeleted.CreationDate), MONTH(PostsWithDeleted.CreationDate), 1) ) AS [Comments], COUNT(PostsWithDeleted.Id) AS [AllPostTypes] FROM PostsWithDeleted GROUP BY DATEFROMPARTS(YEAR(PostsWithDeleted.CreationDate), MONTH(PostsWithDeleted.CreationDate), 1) ORDER BY [Month] ASC ``` More importantly, the graph was also correct: > ![Comments for the Questions, Answers, Wikis TagWikiExcerpts, TagWikis, ModerationNominations, WikiPlaceholders, PrivilegeWikis, AllPostTypes including deleted ones per month (correlated by month)](https://web.archive.org/web/20260119201050if_/https://private-user-images.githubusercontent.com/2033367/537739041-0bbe4aef-977d-48f6-87ce-95e646b08b1b.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njg4NTM3MzAsIm5iZiI6MTc2ODg1MzQzMCwicGF0aCI6Ii8yMDMzMzY3LzUzNzczOTA0MS0wYmJlNGFlZi05NzdkLTQ4ZjYtODdjZS05NWU2NDZiMDhiMWIucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDExOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAxMTlUMjAxMDMwWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZmU5MzQyM2FiMjI3M2RiOWM5ZjRmNGMxZmZkMTAzOTlmOTFkOGU3NmFkMDc3MmI5ZmQ0OGY5NzViOGViNTE3NSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.H9B0ty7MiFHDrhrptHXi6duPTmVQ4pvymA2johAXeuA) Comments for the Questions, Answers, Wikis TagWikiExcerpts, TagWikis, ModerationNominations, WikiPlaceholders, PrivilegeWikis, AllPostTypes including deleted ones per month \(correlated by month\) \[[Wayback](https://web.archive.org/web/20260119201050/https://private-user-images.githubusercontent.com/2033367/537739041-0bbe4aef-977d-48f6-87ce-95e646b08b1b.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njg4NTM3MzAsIm5iZiI6MTc2ODg1MzQzMCwicGF0aCI6Ii8yMDMzMzY3LzUzNzczOTA0MS0wYmJlNGFlZi05NzdkLTQ4ZjYtODdjZS05NWU2NDZiMDhiMWIucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDExOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAxMTlUMjAxMDMwWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZmU5MzQyM2FiMjI3M2RiOWM5ZjRmNGMxZmZkMTAzOTlmOTFkOGU3NmFkMDc3MmI5ZmQ0OGY5NzViOGViNTE3NSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.H9B0ty7MiFHDrhrptHXi6duPTmVQ4pvymA2johAXeuA)/[Archive](https://archive.is/2026.01.19-201047/https://private-user-images.githubusercontent.com/2033367/537739041-0bbe4aef-977d-48f6-87ce-95e646b08b1b.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njg4NTM3MzAsIm5iZiI6MTc2ODg1MzQzMCwicGF0aCI6Ii8yMDMzMzY3LzUzNzczOTA0MS0wYmJlNGFlZi05NzdkLTQ4ZjYtODdjZS05NWU2NDZiMDhiMWIucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDExOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAxMTlUMjAxMDMwWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZmU5MzQyM2FiMjI3M2RiOWM5ZjRmNGMxZmZkMTAzOTlmOTFkOGU3NmFkMDc3MmI5ZmQ0OGY5NzViOGViNTE3NSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.H9B0ty7MiFHDrhrptHXi6duPTmVQ4pvymA2johAXeuA)\][537739041\-0bbe4aef\-977d\-48f6\-87ce\-95e646b08b1b\.png \(981×520\)](https://private-user-images.githubusercontent.com/2033367/537739041-0bbe4aef-977d-48f6-87ce-95e646b08b1b.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njg4NTM3MzAsIm5iZiI6MTc2ODg1MzQzMCwicGF0aCI6Ii8yMDMzMzY3LzUzNzczOTA0MS0wYmJlNGFlZi05NzdkLTQ4ZjYtODdjZS05NWU2NDZiMDhiMWIucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDExOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjAxMTlUMjAxMDMwWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZmU5MzQyM2FiMjI3M2RiOWM5ZjRmNGMxZmZkMTAzOTlmOTFkOGU3NmFkMDc3MmI5ZmQ0OGY5NzViOGViNTE3NSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.H9B0ty7MiFHDrhrptHXi6duPTmVQ4pvymA2johAXeuA) And the graph worries me of the future: besides questions and answers dropping, also the ratio of answers/question and comments/post are dropping\. Bo the ratios are important measures on interaction, and I think less interaction means less quality\. ### Comparing the queries Note that I intentionally left the order of the columns the same in all queries so – sorry if you are not colorblind – you can compare the data across the graphs*except*for the ones in the graph “CommentIdCount by month”\. I wish the SEDE would offer other options than colours to distinguish column data, but they don’t\. If you want build upon these queries multiple times in various directions, then the SEDE by default \(because it prefers linear history\) it allows just one fork, but in practice you can by realising that the[Query Stack Overflow – Stack Exchange Data Explorer: fork “Questions per month including deleted”](https://data.stackexchange.com/stackoverflow/query/fork/1932522)has this URL > [data\.stackexchange\.com/stackoverflow/query/**fork**/1932522](https://data.stackexchange.com/stackoverflow/query/fork/1932522) In a similar way, editing a query has a URL like this: > [data\.stackexchange\.com/stackoverflow/query/**edit**/1933447](https://data.stackexchange.com/stackoverflow/query/edit/1933447) In fact there are at least 6 URL forms for query: > Types of SEDE query URLsFormExampleView[data\.stackexchange\.com/stackoverflow/query/1933447](https://data.stackexchange.com/stackoverflow/query/1933447)View with name[data\.stackexchange\.com/stackoverflow/query/1933447/questions\-answers\-and\-other\-post\-types\-per\-month\-including\-deleted](https://data.stackexchange.com/stackoverflow/query/1933447/questions-answers-and-other-post-types-per-month-including-deleted)Edit[data\.stackexchange\.com/stackoverflow/query/edit/1933447](https://data.stackexchange.com/stackoverflow/query/edit/1933447)Fork[data\.stackexchange\.com/stackoverflow/query/fork/1933447](https://data.stackexchange.com/stackoverflow/query/fork/1933447)View with revision[data\.stackexchange\.com/stackoverflow/revision/1933447/2375006](https://data.stackexchange.com/stackoverflow/revision/1933447/2375006)View with revision and name[data\.stackexchange\.com/stackoverflow/revision/1933447/2375006/questions\-answers\-and\-other\-post\-types\-per\-month\-including\-deleted](https://data.stackexchange.com/stackoverflow/revision/1933447/2375006/questions-answers-and-other-post-types-per-month-including-deleted) All of these can have various fragments to switch the results view into various modes or direct focus to various inputs: > Type of SEDE query fragments \(including their \#\)FragmentMeaning`\#result`Results view`\#resultSets`Results view`\#messages`Messages view`\#graph`Graph view`\#executionPlan`Execution plan view \(only visible when “Include execution plan” is checked before running the query\)`\#edit\-query\-description`Query description text area`\#sql`SQL text area`\#query\-params`Query parameters edits \(only visible when there are query parameters\)`\#site\-selector`Site selector pane`\#switch\-sites`Site selector query inputThere are more fragments, but these do not set focus\. I got to the above tables because these were in my query history: > - [https://data\.stackexchange\.com/stackoverflow/revision/1933385/2374944/answers\-per\-month\-including\-deleted](https://data.stackexchange.com/stackoverflow/revision/1933385/2374944/answers-per-month-including-deleted) - [https://data\.stackexchange\.com/stackoverflow/revision/1933447/2375006/questions\-answers\-and\-other\-post\-types\-per\-month\-including\-deleted](https://data.stackexchange.com/stackoverflow/revision/1933447/2375006/questions-answers-and-other-post-types-per-month-including-deleted) - [https://data\.stackexchange\.com/stackoverflow/query/1933489/comments\-for\-questions\-answers\-and\-other\-posts\-per\-month\-including\-deleted](https://data.stackexchange.com/stackoverflow/query/1933489/comments-for-questions-answers-and-other-posts-per-month-including-deleted) - [https://data\.stackexchange\.com/stackoverflow/query/edit/1933447](https://data.stackexchange.com/stackoverflow/query/edit/1933447) - [https://data\.stackexchange\.com/stackoverflow/revision/1933447/2367378/questions\-answers\-and\-other\-post\-types\-per\-month\-including\-deleted](https://data.stackexchange.com/stackoverflow/revision/1933447/2367378/questions-answers-and-other-post-types-per-month-including-deleted) - [https://data\.stackexchange\.com/stackoverflow/query/edit/1933489](https://data.stackexchange.com/stackoverflow/query/edit/1933489) - [https://data\.stackexchange\.com/stackoverflow/query/edit/1933447\#graph](https://data.stackexchange.com/stackoverflow/query/edit/1933447#graph) - [https://data\.stackexchange\.com/stackoverflow/query/edit/1933447\#messages](https://data.stackexchange.com/stackoverflow/query/edit/1933447#messages) - [https://data\.stackexchange\.com/stackoverflow/revision/1932522/2374035/questions\-per\-month\-including\-deleted\#graph](https://data.stackexchange.com/stackoverflow/revision/1932522/2374035/questions-per-month-including-deleted#graph) - [https://data\.stackexchange\.com/stackoverflow/query/fork/1932522](https://data.stackexchange.com/stackoverflow/query/fork/1932522) - [https://data\.stackexchange\.com/stackoverflow/query/edit/1933385\#graph](https://data.stackexchange.com/stackoverflow/query/edit/1933385#graph) - [https://data\.stackexchange\.com/stackoverflow/query/1933385/answers\-per\-month\-including\-deleted](https://data.stackexchange.com/stackoverflow/query/1933385/answers-per-month-including-deleted) - [https://data\.stackexchange\.com/stackoverflow/revision/1933385/2374944/answers\-per\-month\-including\-deleted\#messages](https://data.stackexchange.com/stackoverflow/revision/1933385/2374944/answers-per-month-including-deleted#messages) - [https://data\.stackexchange\.com/stackoverflow/revision/1932522/2367458/questions\-per\-month\-including\-deleted](https://data.stackexchange.com/stackoverflow/revision/1932522/2367458/questions-per-month-including-deleted) - [https://data\.stackexchange\.com/stackoverflow/revision/1932522/2367378/questions\-per\-month\-including\-deleted](https://data.stackexchange.com/stackoverflow/revision/1932522/2367378/questions-per-month-including-deleted) - [https://data\.stackexchange\.com/stackoverflow/query/1933447/questions\-answers\-and\-other\-post\-types\-per\-month\-including\-deleted\#graph](https://data.stackexchange.com/stackoverflow/query/1933447/questions-answers-and-other-post-types-per-month-including-deleted#graph) - [https://data\.stackexchange\.com/stackoverflow/query/edit/1933448\#graph](https://data.stackexchange.com/stackoverflow/query/edit/1933448#graph) - [https://data\.stackexchange\.com/stackoverflow/query/new](https://data.stackexchange.com/stackoverflow/query/new) - [https://data\.stackexchange\.com/stackoverflow/query/edit/1933449\#resultSets](https://data.stackexchange.com/stackoverflow/query/edit/1933449#resultSets) - [https://data\.stackexchange\.com/stackoverflow/query/1933449/total\-posts\-and\-comments](https://data.stackexchange.com/stackoverflow/query/1933449/total-posts-and-comments) - [https://data\.stackexchange\.com/stackoverflow/query/edit/1933462\#graph](https://data.stackexchange.com/stackoverflow/query/edit/1933462#graph) - [https://data\.stackexchange\.com/stackoverflow/query/edit/1933642](https://data.stackexchange.com/stackoverflow/query/edit/1933642) - [https://data\.stackexchange\.com/stackoverflow/query/1933642/comments\-count\-by\-month](https://data.stackexchange.com/stackoverflow/query/1933642/comments-count-by-month) - [https://data\.stackexchange\.com/stackoverflow/revision/1933642/2375208/comments\-count\-by\-month](https://data.stackexchange.com/stackoverflow/revision/1933642/2375208/comments-count-by-month) - [https://data\.stackexchange\.com/stackoverflow/revision/1933642/2375209/comments\-count\-by\-month](https://data.stackexchange.com/stackoverflow/revision/1933642/2375209/comments-count-by-month) - [https://data\.stackexchange\.com/stackoverflow/revision/1933642/2375210/comments\-count\-by\-month](https://data.stackexchange.com/stackoverflow/revision/1933642/2375210/comments-count-by-month) - [https://data\.stackexchange\.com/stackoverflow/revision/1933447/2375558/comments\-for\-questions\-answers\-and\-other\-post\-types\-per\-month\-incl\-deleted\-cor](https://data.stackexchange.com/stackoverflow/revision/1933447/2375558/comments-for-questions-answers-and-other-post-types-per-month-incl-deleted-cor) The above URL table also means that you can edit anyone elses queries \(in essence creating a fork of it\) like[data\.stackexchange\.com/stackoverflow/query/**edit**/1932522](https://data.stackexchange.com/stackoverflow/query/edit/1932522) I did and ended up with the above four forks all stemming from query 1932522:[Questions per month including deleted – Stack Exchange Data Explorer](https://data.stackexchange.com/stackoverflow/query/1932522/questions-per-month-including-deleted): 1. 1933385:[Answers per month including deleted – Stack Exchange Data Explorer](https://data.stackexchange.com/stackoverflow/query/1933385/answers-per-month-including-deleted) 2. 1933447:[Questions, answers and other post types per month including deleted – Stack Exchange Data Explorer](https://data.stackexchange.com/stackoverflow/query/1933447/questions-answers-and-other-post-types-per-month-including-deleted)1. 1933489:[Comments for questions, answers and other posts per month including deleted – Stack Exchange Data Explorer](https://data.stackexchange.com/stackoverflow/query/1933489/comments-for-questions-answers-and-other-posts-per-month-including-deleted) 2. 1933447:[Comments for questions, answers and other post types per month incl\. deleted \(correlated by month\) – Stack Exchange Data Explorer](https://data.stackexchange.com/stackoverflow/query/1933447/comments-for-questions-answers-and-other-post-types-per-month-incl-deleted-cor) Of course, I could have forked 2\.2\. from 2\.1\. but then I could not have shown you can fork your own queries\. What I did was forking[Questions, answers and other post types per month including deleted – Stack Exchange Data Explorer](https://data.stackexchange.com/stackoverflow/revision/1933447/2375006/questions-answers-and-other-post-types-per-month-including-deleted)to create a second history tree by editing > [data\.stackexchange\.com/stackoverflow/revision/**1933447**/2375006/questions\-answers\-and\-other\-post\-types\-per\-month\-including\-deleted](https://data.stackexchange.com/stackoverflow/revision/1933447/2375006/questions-answers-and-other-post-types-per-month-including-deleted) into > [data\.stackexchange\.com/stackoverflow/query/**fork**/1933447](https://data.stackexchange.com/stackoverflow/query/fork/1933447) So if I want to fork[Comments for questions, answers and other posts per month including deleted – Stack Exchange Data Explorer](https://data.stackexchange.com/stackoverflow/query/1933489/comments-for-questions-answers-and-other-posts-per-month-including-deleted)as well, now i know how\! ### Stack Exchange Data Explorer \(SEDE\) The above graphs were made using the Stack Exchange Data Explorer \(SEDE\)\. Some links on it’s basics: - \[[Wayback](https://web.archive.org/web/20260115183317/https://html.duckduckgo.com/html?q=Stack+Exchange+Data+Explorer+(SEDE))/[Archive](https://archive.is/2026.01.15-183226/https://html.duckduckgo.com/html?q=Stack+Exchange+Data+Explorer+(SEDE))\][Stack Exchange Data Explorer \(SEDE\) at DuckDuckGo](https://html.duckduckgo.com/html?q=Stack+Exchange+Data+Explorer+(SEDE)) - \[[Wayback](https://web.archive.org/web/20260117162217/https://meta.stackexchange.com/questions/49424/introducing-the-stack-exchange-data-explorer-aka-sede)/[Archive](https://archive.is/2026.01.15-193234/https://meta.stackexchange.com/questions/49424/introducing-the-stack-exchange-data-explorer-aka-sede)\][Introducing the Stack Exchange Data Explorer aka SEDE – Meta Stack Exchange](https://meta.stackexchange.com/questions/49424/introducing-the-stack-exchange-data-explorer-aka-sede)was the original 2010 introduction post - \[[Wayback](https://web.archive.org/web/20251124211402/https://blog.stackoverflow.com/2010/06/introducing-stack-exchange-data-explorer/)/[Archive](https://archive.is/2026.01.15-183844/https://blog.stackoverflow.com/2010/06/introducing-stack-exchange-data-explorer/)\][Introducing Stack Exchange Data Explorer – Stack Overflow](https://blog.stackoverflow.com/2010/06/introducing-stack-exchange-data-explorer/)is a better introduction than the above post - \[[Wayback](https://web.archive.org/web/20260115183227/https://github.com/hirupert/sede)/[Archive](https://archive.is/2026.01.15-183304/https://github.com/hirupert/sede)\][GitHub – hirupert/sede: Text\-to\-SQL in the Wild: A Naturally\-Occurring Dataset Based on Stack Exchange Data](https://github.com/hirupert/sede) - \[[Wayback](https://web.archive.org/web/20260115183334/https://peter-whyte.com/2018/07/stack-exchange-data-explorer/)/[Archive](https://archive.is/2026.01.15-183352/https://peter-whyte.com/2018/07/stack-exchange-data-explorer/)\][What is Stack Exchange Data Explorer \(SEDE\)? – SQL DBA Blog](https://peter-whyte.com/2018/07/stack-exchange-data-explorer/) SEDE used to be a great playground to learn SQL, but the current rate limiting makes it less useful for that\. That means that by now, the best way to use it is with good enough SQL knowledge and a grasp of the Stack Exchange data model\. For the last part, these links will help: - \[[Wayback](https://web.archive.org/web/20260118105123/https://meta.stackexchange.com/questions/2677/database-schema-documentation-for-the-public-data-dump-and-sede)/[Archive](https://archive.is/2026.01.18-145547/https://meta.stackexchange.com/questions/2677/database-schema-documentation-for-the-public-data-dump-and-sede)\][Database schema documentation for the public data dump and SEDE – Meta Stack Exchange](https://meta.stackexchange.com/questions/2677/database-schema-documentation-for-the-public-data-dump-and-sede) - \[[Wayback](https://web.archive.org/web/20250813192032/https://data.stackexchange.com/stackoverflow/query/36599/show-all-types)/[Archive](https://archive.is/2025.08.13-192032/https://data.stackexchange.com/stackoverflow/query/36599/show-all-types)\][Show all types – Stack Exchange Data Explorer](https://data.stackexchange.com/stackoverflow/query/36599/show-all-types)\(`Id`s and`Name`s for`PostTypes`,`CloseAsOffTopicReasonTypes`,`CloseReasonTypes`,`FlagTypes`,`PostHistoryTypes`,`PostNoticeTypes`,`VoteTypes`,`ReviewTaskResultTypes`,`ReviewTaskTypes`\) - \[[Wayback](https://web.archive.org/web/20260115130012/https://data.stackexchange.com/)/[Archive](https://archive.is/2025.02.25-080843/https://data.stackexchange.com/)\][Stack Exchange Data Explorer](https://data.stackexchange.com/)has statistics for all Stack Exchange sites; I never before noticed that Mathematics made it to the second place in between Stack Overflow and Super User\. - \[[Wayback](https://web.archive.org/web/20220816010425/https://data.stackexchange.com/tutorial/next-steps)/[Archive](https://archive.is/2022.08.16-010425/https://data.stackexchange.com/tutorial/next-steps)\][Next Steps – Stack Exchange Data Explorer](https://data.stackexchange.com/tutorial/next-steps)is the end of the SQL tutorial and has some useful links - \[[Wayback](https://web.archive.org/web/20260118103951/https://worldbuilding.meta.stackexchange.com/questions/2013/worldbuilding-data-queries/2014)/[Archive](https://archive.is/2026.01.18-104143/https://worldbuilding.meta.stackexchange.com/questions/2013/worldbuilding-data-queries/2014)\][Worldbuilding Data Queries – Worldbuilding Meta Stack Exchange](https://worldbuilding.meta.stackexchange.com/questions/2013/worldbuilding-data-queries/2014)has a lot of nice queries all neatly described and categorised\. - \[[Wayback](https://web.archive.org/web/20251211070634/https://data.stackexchange.com/meta.stackexchange/queries)/[Archive](https://archive.is/2025.12.11-070634/https://data.stackexchange.com/meta.stackexchange/queries)\][Browse Queries – Stack Exchange Data Explorer](https://data.stackexchange.com/meta.stackexchange/queries)– featured queries applied to Meta Stack Exchange - \[[Wayback](https://web.archive.org/web/20250905160741/https://data.stackexchange.com/stackoverflow/queries)/[Archive](https://archive.is/2025.09.05-160741/https://data.stackexchange.com/stackoverflow/queries)\][Browse Queries – Stack Exchange Data Explorer](https://data.stackexchange.com/stackoverflow/queries)– the same featured queries applied to Stack Overflow - \[[Wayback](https://web.archive.org/web/20250421214238/https://data.stackexchange.com/stackoverflow/queries?order_by=popular)/[Archive](https://archive.is/2025.04.21-214238/https://data.stackexchange.com/stackoverflow/queries?order_by=popular)\][Browse Queries – Stack Exchange Data Explorer: popular](https://data.stackexchange.com/stackoverflow/queries?order_by=popular)\(on Stack Overflow\) is measured by view count - \[[Wayback](https://web.archive.org/web/20250425150613/https://data.stackexchange.com/stackoverflow/queries?order_by=favorite)/[Archive](https://archive.is/2025.04.25-150613/https://data.stackexchange.com/stackoverflow/queries?order_by=favorite)\][Browse Queries – Stack Exchange Data Explorer: favorite](https://data.stackexchange.com/stackoverflow/queries?order_by=favorite)\(on Stack Overflow\) is a kind of upvoting, but for queries a A few more useful links on SEDE: - \[[Wayback](https://web.archive.org/web/20210507114151/https://data.stackexchange.com/stackoverflow/query/1)/[Archive](https://archive.is/2021.05.07-114151/https://data.stackexchange.com/stackoverflow/query/1)\][– Stack Exchange Data Explorer](https://data.stackexchange.com/stackoverflow/query/1)is unnamed, but shows how to use a temporary table combined with`set nocount on`to show posts with large downvote/upvote rations, of which the SQL incidentally showed the same method as I used for the graph with all post types\. - \[[Wayback](https://web.archive.org/web/20260118104526/https://meta.stackexchange.com/questions/416682/how-can-i-have-a-parameter-in-sede-that-can-be-compared-with-multiple-datetime-v/416683)/[Archive](https://archive.is/2026.01.18-104652/https://meta.stackexchange.com/questions/416682/how-can-i-have-a-parameter-in-sede-that-can-be-compared-with-multiple-datetime-v/416683)\][How can I have a parameter in SEDE that can be compared with multiple DATETIME values? – Meta Stack Exchange](https://meta.stackexchange.com/questions/416682/how-can-i-have-a-parameter-in-sede-that-can-be-compared-with-multiple-datetime-v/416683)\(thanks \[[Wayback](https://web.archive.org/web/20260118104653/https://meta.stackexchange.com/users/997587/starball)/[Archive](https://archive.is/2026.01.18-104745/https://meta.stackexchange.com/users/997587/starball)\][starball](https://meta.stackexchange.com/users/997587/starball)and \[[Wayback](https://web.archive.org/web/20260118104655/https://meta.stackexchange.com/users/295232/glorfindel)/[Archive](https://archive.is/2026.01.18-104707/https://meta.stackexchange.com/users/295232/glorfindel)\][Glorfindel](https://meta.stackexchange.com/users/295232/glorfindel)\) which in the linked example shows:- passing passing parameters by URL - setting the data type for a parameter - shows the`Id AS \[Post Link\]`trick to get links to posts > Looks like SEDE doesn’t like underscores in parameter names?[This](https://data.stackexchange.com/meta.stackexchange/query/1926606?dateParam=2025-12-25)works for me: ``` SELECT Id AS [Post Link], LastEditDate, LastActivityDate FROM Posts WHERE LastEditDate >= ##dateParam:string## OR LastActivityDate >= ##dateParam:string## ``` Note that you must declare date parameters as a string, otherwise I think it’s trying to calculate`2025 \- 12 \- 15 = 1988`or something, and I get basically the entire table back\. Linked query: \[[ArchiveSave](https://archive.is/?run=1&url=https://data.stackexchange.com/meta.stackexchange/query/1926606?dateParam=2025-12-25)\][data\.stackexchange\.com/meta\.stackexchange/query/1926606**?dateParam=2025\-12\-25**](https://data.stackexchange.com/meta.stackexchange/query/1926606?dateParam=2025-12-25) - \[[Wayback](https://web.archive.org/web/20220816042337/https://data.stackexchange.com/meta.stackexchange/query/53058/top-users-by-country)/[Archive](https://archive.is/2022.08.16-042337/https://data.stackexchange.com/meta.stackexchange/query/53058/top-users-by-country)\][Top Users by Country – Stack Exchange Data Explorer](https://data.stackexchange.com/meta.stackexchange/query/53058/top-users-by-country)shows the`Id AS \[User Link\]`trick to get links to users\. - \[[Wayback](https://web.archive.org/web/20250421152605/https://data.stackexchange.com/stackoverflow/query/1181/vanity-search-links-to-my-website-posted-by-other-people-during-last-2-months)/[Archive](https://archive.is/2025.04.21-152605/https://data.stackexchange.com/stackoverflow/query/1181/vanity-search-links-to-my-website-posted-by-other-people-during-last-2-months)\][Vanity search: links to my website posted by other people during last 2 months – Stack Exchange Data Explorer](https://data.stackexchange.com/stackoverflow/query/1181/vanity-search-links-to-my-website-posted-by-other-people-during-last-2-months) Note that Stack Exchange is giving both the Wayback Machine and Archive\.is a hard time archiving SEDE links, see for instance the \[[Wayback](https://web.archive.org/web/20260118113510/https://data.stackexchange.com/web/20260118113510/https://data.stackexchange.com/meta.stackexchange/query/1926606?dateParam=2025-12-25)\] of the last linked query above\. That’s a pity, as with the decline of Stack Exchange, it might go off\-line one day taking all kinds of historically relevant data with it\. ### Via 1. \[[Wayback](https://web.archive.org/web/20260115194509/https://bsky.app/profile/wiert.bsky.social/post/3mchxshrtgc2z)/[Archive](https://archive.is/2026.01.15-194353/https://bsky.app/profile/wiert.bsky.social/post/3mchxshrtgc2z)\][Post by @wiert\.bsky\.social — Bluesky: Source](https://bsky.app/profile/wiert.bsky.social/post/3mchxshrtgc2z) 2. \[[Wayback](https://web.archive.org/web/20260115194553/https://html.duckduckgo.com/html?q=Sherwood+News+Stack+Overflow%27s+Forum%27s+Decline+Started+Years+Ago%2C+But+Al+Killed+The+Platform+For+Good)/[Archive](https://archive.is/2026.01.15-194446/https://html.duckduckgo.com/html?q=Sherwood+News+Stack+Overflow%27s+Forum%27s+Decline+Started+Years+Ago,+But+Al+Killed+The+Platform+For+Good)\][Sherwood News Stack Overflow’s Forum’s Decline Started Years Ago, But Al Killed The Platform For Good at DuckDuckGo](https://html.duckduckgo.com/html?q=Sherwood+News+Stack+Overflow%27s+Forum%27s+Decline+Started+Years+Ago,+But+Al+Killed+The+Platform+For+Good) `\-\-`jeroen PS: My favorite queries are listed at[User Jeroen\.Wiert\.Pluimers – Stack Exchange Data Explorer](https://data.stackexchange.com/users/49598/jeroen-wiert-pluimers?order_by=favorite)\. Regrettably, this long cannot be archived, so I quoted the list at the time of finishing this blog post: > - [Comments for questions, answers and other posts per month including deleted](https://data.stackexchange.com/stackoverflow/query/1933489/comments-for-questions-answers-and-other-posts-per-month-including-deleted) - [Comments count by Month](https://data.stackexchange.com/stackoverflow/query/1933642/comments-count-by-month) - [Total Posts and Comments](https://data.stackexchange.com/stackoverflow/query/1933449/total-posts-and-comments) - [Comments for questions, answers and other post types per month incl\. deleted \(correlated by month\)](https://data.stackexchange.com/stackoverflow/query/1933447/comments-for-questions-answers-and-other-post-types-per-month-incl-deleted-cor) - [Answers per month including deleted](https://data.stackexchange.com/stackoverflow/query/1933385/answers-per-month-including-deleted) - [Questions per month including deleted](https://data.stackexchange.com/stackoverflow/query/1932522/questions-per-month-including-deleted) - [Total Questions and Answers per Month for the last 12](https://data.stackexchange.com/stackoverflow/query/6134/total-questions-and-answers-per-month-for-the-last-12)

Similar Articles

API Partnership with Stack Overflow

OpenAI Blog

OpenAI and Stack Overflow announce a strategic partnership to integrate Stack Overflow's OverflowAPI and verified developer knowledge into ChatGPT and OpenAI models, while Stack Overflow will leverage OpenAI's models for their OverflowAI product. The collaboration aims to improve AI model performance for developers with accurate, attributed technical knowledge from the 59-million-question developer community.

Is traditional SEO slowly dying because of AI agents?

Reddit r/AI_Agents

Discussion on how AI agents like ChatGPT, Perplexity, and Claude are shifting user search behavior away from traditional Google searches, potentially making SEO less about ranking articles and more about brand authority and structured data.

Nobody cracks open a programming book anymore

Hacker News Top

This article examines the steep decline in programming book sales as AI chatbots like ChatGPT and GitHub Copilot replace traditional learning methods, noting a 16.9% drop in 2023 and publishers ceasing to report the category.