QuerySetId
uint32
466
1.35M
Title
stringlengths
4
100
Description
stringlengths
1
994
QueryBody
stringlengths
1
799
CreationDate
stringlengths
19
19
validated
bool
1 class
466
Most controversial posts on the site
Looks for posts with more than half the amount of downvotes as they have upvotes Ordered by upvotes
SELECT * from Votes
2020-06-24 11:23:10
false
784
Comments asking for questions to be made wiki
All comments that contain the text should and wiki
SELECT PostId as [Post Link], Text from Comments where Text like '%should%wiki%'
2019-07-07 11:01:51
false
785
How many upvotes do I have for each tag?
how long before I get tag badges?
DECLARE @UserId int = ##UserId## SELECT --TOP 20 TagName, COUNT(*) AS UpVotes, COUNT(Posts.Id) FROM Tags INNER JOIN PostTags ON PostTags.TagId = Tags.id INNER JOIN Posts ON Posts.ParentId = PostTags.PostId INNER JOIN Votes ON Votes.PostId = Posts.Id and VoteTypeId = 2 WHERE Posts.OwnerUserId = @UserId GROUP BY TagName ORDER BY UpVotes DESC
2020-12-06 01:47:00
false
873
Posts containing a very short body
Posts containing a body that is less than 8 chars long
SELECT Id as [Post Link], Body, Score from Posts where Len(Body) < 64 AND Title <> 'undefined'
2020-11-30 04:11:17
false
877
Posts containing a very short title
Posts containing a body that is less than 5 chars long
SELECT Id as [Post Link], Body, Score from Posts where Len(Title) < 20 and ParentId is null
2020-11-25 01:19:00
false
886
Posts with many "thank you" answers
Looking at posts shorter than 200 with the text `hank` somewhere in it
SELECT ParentId as [Post Link], count(id) from posts where posttypeid = 2 and len(body) <= 200 and (body like '%hey i%') group by parentid having count(id) > 1 order by count(id) desc;
2020-11-30 02:23:24
false
949
What is my accepted answer percentage rate
On avg how often are answers I give, accepted
DECLARE @UserId int = 2270762 SELECT COUNT(*) as answers, COUNT(q.id) as accepted, CAST(Count(q.id) AS float) / COUNT(*) * 100 AS AcceptedPercentage FROM Posts a LEFT JOIN Posts q ON q.AcceptedAnswerId = a.Id WHERE a.PostTypeId = 2
2020-07-15 21:05:30
false
951
Low views, high votes yet unanswered
A list of questions with a high score and low view count
SELECT TOP 100 questao.Id as [Post Link], questao.Score, questao.ViewCount, comentario.Id, comentario.Score as socre_comentario, comentario.ViewCount as views_comentario FROM Posts questao JOIN Posts comentario ON questao.id = comentario.ParentId WHERE questao.Tags like '%<android%' --AND questao.CreationDate >= '01/01/2018' AND questao.ParentId is null ORDER BY questao.ViewCount ASC
2020-04-04 04:29:48
false
952
Top 500 answerers on the site
A list of the top 500 users with the highest average answer score excluding community wiki / closed posts or users with less than 10 answers
SELECT TOP 500 Users.Id as [User Link], Count(Posts.Id) AS Answers, CAST(AVG(CAST(Score AS float)) as numeric(6,2)) AS [Average Answer Score] FROM Posts INNER JOIN Users ON Users.Id = OwnerUserId WHERE PostTypeId = 2 and CommunityOwnedDate is null and ClosedDate is null GROUP BY Users.Id, DisplayName HAVING Count(Posts.Id) > 10 ORDER BY [Average Answer Score] DESC
2020-11-28 22:11:05
false
975
Users with more than one duplicate account and a more than 1000 reputation in aggregate
A list of users that have duplicate accounts on site, based on the EmailHash and lots of reputation is riding on it
WITH more than one duplicate account and a more that 1000 reputation in aggregate -- A list of users that have duplicate accounts on site, based on the EmailHash and lots of reputation is riding on it SELECT u1.EmailHash, Count(u1.Id) AS Accounts, ( SELECT Cast(u2.Id AS varchar) + ' (' + u2.DisplayName + ' ' + Cast(u2.reputation as varchar) + '), ' FROM Users u2 WHERE u2.EmailHash = u1.EmailHash order by u2.Reputation desc FOR XML PATH ('')) AS IdsAndNames FROM Users u1 WHERE u1.EmailHash IS NOT NULL and (select count(*) from Users u3 where u3.EmailHash = u1.EmailHash and Reputation > 10) > 1 GROUP BY u1.EmailHash HAVING Count(u1.Id) > 1 ORDER BY Accounts DESC
2019-05-23 00:03:12
false
1,080
Top Users by Number of Bounties Won
null
SELECT Top 300 Posts.OwnerUserId As [User Link], COUNT(*) As BountiesWon FROM Votes INNER JOIN Posts ON Votes.PostId = Posts.Id WHERE VoteTypeId=9 GROUP BY Posts.OwnerUserId ORDER BY BountiesWon DESC
2020-09-24 00:04:31
false
1,484
Badge CreationDate is always NULL (IS THIS A BUG?)
null
SELECT Name, (SELECT Count(*) FROM Badges B WHERE B.Name=C.Name AND CreationDate Is NULL) As [CountNull], (SELECT Count(*) FROM Badges B WHERE B.Name=C.Name AND CreationDate Is NOT NULL) As [CountNotNull] FROM Badges C Group By Name
2010-05-28 06:35:30
false
1,619
New user signup rates (SuperUser)
null
WITH graph select [Month], count(*) Users from ( select CAST( cast(DATEPART(YYYY, CreationDate) as varchar) + '-' + cast(DATEPART(MM, CreationDate) as varchar) + '-01' as datetime) [Month] from Users p ) as X group by [Month] order by [Month] asc
2012-08-16 13:45:41
false
1,682
Check Votes.CreationDate is always a date
null
SELECT Name, Count(*)as [Count], DatePart(Hour, Votes.CreationDate)as [hour],DatePart(Minute, Votes.CreationDate)as [minute],DatePart(Second, Votes.CreationDate)as [second],DatePart(Millisecond, Votes.CreationDate)as [ms] FROM Votes JOIN VoteTypes ON VoteTypeId = VoteTypes.Id GROUP BY Name, DatePart(Hour, Votes.CreationDate),DatePart(Minute, Votes.CreationDate),DatePart(Second, Votes.CreationDate),DatePart(Millisecond, Votes.CreationDate)
2010-05-29 03:25:23
false
1,703
Up vs Down votes by week day
null
SELECT DATENAME(WEEKDAY, CreationDate) AS Day, Count(*) AS Amount, SUM(CASE WHEN VoteTypeId = 2 THEN 1 ELSE 0 END) AS UpVotes, SUM(CASE WHEN VoteTypeId = 3 THEN 1 ELSE 0 END) AS DownVotes, (CAST(SUM(CASE WHEN VoteTypeId = 2 THEN 1 ELSE 0 END) AS float) / CAST(SUM(CASE WHEN VoteTypeId = 3 THEN 1 ELSE 0 END) AS float)) AS UpVoteDownVoteRatio FROM Votes GROUP BY DATENAME(WEEKDAY, CreationDate), DATEPART(WEEKDAY, CreationDate) ORDER BY DATEPART(WEEKDAY, CreationDate)
2010-05-29 07:17:20
false
1,717
Up vs Down votes by hour of day of Question or Answer
null
SELECT CASE WHEN PostTypeId = 1 THEN 'Question' ELSE 'Answer' END As [Post Type], DATEPART(HOUR, p.CreationDate) AS Hour, Count(*) AS Amount, SUM(CASE WHEN VoteTypeId = 2 THEN 1 ELSE 0 END) AS UpVotes, SUM(CASE WHEN VoteTypeId = 3 THEN 1 ELSE 0 END) AS DownVotes, (CAST(SUM(CASE WHEN VoteTypeId = 2 THEN 1 ELSE 0 END) AS float) / CAST(SUM(CASE WHEN VoteTypeId = 3 THEN 1 ELSE 0 END) AS float)) AS UpVoteDownVoteRatio FROM Votes v JOIN Posts p ON v.PostId=p.Id WHERE PostTypeId In (1,2) AND VoteTypeId In (2,3) GROUP BY PostTypeId, DATEPART(HOUR, p.CreationDate) ORDER BY PostTypeId, DATEPART(HOUR, p.CreationDate)
2012-06-06 19:45:20
false
1,718
Up vs Down votes by day of week of Question or Answer
null
SELECT TOP 50 p.Id as [Post Link], CASE WHEN PostTypeId = 1 THEN 'Question' ELSE 'Answer' END As [Post Type], --DATENAME(WEEKDAY, p.CreationDate) AS Day, SUM(CASE WHEN VoteTypeId = 2 THEN 1 ELSE 0 END) AS UpVotes, SUM(CASE WHEN VoteTypeId = 3 THEN 1 ELSE 0 END) AS DownVotes FROM Votes v JOIN Posts p ON v.PostId=p.Id WHERE PostTypeId In (1) AND VoteTypeId In (2,3) and CommunityOwnedDate is null and ClosedDate is null and AcceptedAnswerId is null and YEAR(p.CreationDate) = 2020 GROUP BY p.Id, PostTypeId HAVING SUM(CASE WHEN VoteTypeId = 2 THEN 1 ELSE 0 END) = 0 ORDER BY DownVotes desc
2020-05-04 15:31:23
false
1,782
Up vs Down votes by hour of week of Question or Answer
null
SELECT CASE WHEN PostTypeId = 1 THEN 'Question' ELSE 'Answer' END As [Post Type], DATENAME(WEEKDAY, p.CreationDate) AS [Day], DATEPART(HOUR, p.CreationDate) AS [Hour], Count(*) AS Amount, SUM(CASE WHEN VoteTypeId = 2 THEN 1 ELSE 0 END) AS UpVotes, SUM(CASE WHEN VoteTypeId = 3 THEN 1 ELSE 0 END) AS DownVotes, (CAST(SUM(CASE WHEN VoteTypeId = 2 THEN 1 ELSE 0 END) AS float) / CAST(SUM(CASE WHEN VoteTypeId = 3 THEN 1 ELSE 0 END) AS float)) AS UpVoteDownVoteRatio FROM Votes v JOIN Posts p ON v.PostId=p.Id GROUP BY PostTypeId, DATEPART(WEEKDAY, p.CreationDate), DATENAME(WEEKDAY, p.CreationDate), DATEPART(HOUR, p.CreationDate) ORDER BY PostTypeId, --DATEPART(WEEKDAY, p.CreationDate), DATEPART(HOUR, p.CreationDate) 7
2010-05-29 17:58:51
false
1,919
Average Answerer's Age (among the tags answered by more than 1000 users with age filled)
null
SELECT TagName AS Tags, AVG(Age * 1.0) AS [Average Answerer's Age], COUNT(*) AS [Number of Answerers] FROM ( SELECT DISTINCT pa.OwnerUserId, pt.TagId FROM Users u JOIN Posts pa ON pa.OwnerUserId = U.Id JOIN Posts pq ON pq.Id = pa.ParentId JOIN PostTags pt ON pt.PostId = pq.Id ) ut JOIN Tags t ON t.Id = ut.TagId JOIN Users u ON u.Id = ut.OwnerUserId WHERE u.Age BETWEEN 10 AND 90 GROUP BY t.Id, t.TagName HAVING COUNT(*) > 1000 ORDER BY 2 DESC*/ SELECT * From Users
2020-01-21 07:02:11
false
1,933
Users with high self-accept rates (and having > 10 answers)
(the extreme self-learners)
SELECT TOP 100 Users.Id AS [User Link], (CAST(Count(a.Id) AS float) / CAST((SELECT Count(*) FROM Posts p WHERE p.OwnerUserId = Users.Id AND PostTypeId = 1) AS float) * 100) AS SelfAnswerPercentage FROM Posts q INNER JOIN Posts a ON q.AcceptedAnswerId = a.Id INNER JOIN Users ON Users.Id = q.OwnerUserId WHERE q.OwnerUserId = a.OwnerUserId GROUP BY Users.Id, DisplayName HAVING Count(a.Id) > 20 ORDER BY SelfAnswerPercentage DESC
2020-02-22 19:02:24
false
2,142
Find people from a company
Enter a company name to search for people working at that company
SELECT Users.Id as [User Link], Users.Reputation FROM Users WHERE lower(Users.AboutMe) LIKE lower('%##CompanyName##%') ORDER BY Users.Reputation desc
2020-08-03 19:18:18
false
2,305
Posts containing bit.ly shortened URLs
Posts containing bit.ly shortened URLs, which allow for tracking clicks :-( See http://meta.stackoverflow.com/questions/29518/can-and-should-stack-overflow-automatically-rewrite-bit-ly-links See http://stackapps.com/questions/121/what-ideas-do-you-have-for-the-api/546#546
SELECT Id as [Post Link], Body from Posts where Body like '%http://bit.ly%'
2010-06-05 16:54:37
false
2,357
How many upvotes do I have towards tag-specialist badges?
null
DECLARE @UserId int = ##UserId## SELECT TOP 500 TagName, COUNT(*) AS UpVotes FROM Tags INNER JOIN PostTags ON PostTags.TagId = Tags.id INNER JOIN Posts ON Posts.ParentId = PostTags.PostId INNER JOIN Votes ON Votes.PostId = Posts.Id and VoteTypeId = 2 WHERE Posts.OwnerUserId = @UserId AND Posts.CommunityOwnedDate IS NULL GROUP BY TagName ORDER BY UpVotes DESC
2020-07-23 13:58:56
false
2,471
Worst 100 Askers from the top 1500 by question count on the site
A list of the bottom 100 askers of questions ordered by average answer score excluding community wiki / closed posts, from the top 1500 by question count
SELECT TOP 100 * FROM ( SELECT TOP 1500 OwnerUserId as [User Link], Count(Posts.Id) AS Questions, CAST(AVG(CAST(Score AS float)) as numeric(6,2)) AS [Average Question Score] FROM Posts WHERE PostTypeId = 1 and CommunityOwnedDate is null and ClosedDate is null GROUP BY OwnerUserId ORDER BY Count(Posts.Id) DESC )D ORDER BY [Average Question Score] ASC
2010-06-07 17:44:41
false
2,666
Most common tags with singular and plural version (s-plural)
Tags which that have singular and plural version (with s-plural). For example [database] and [database].
WITH singular and plural version (s-plur -- Tags which that have singular and plural version (WITH s-plural). -- For example [database] and [database]. select ( select count(*) AS cnts from posttags pts where pts.TagId = t1.id) + ( select count(*) AS cnts from posttags pts where pts.TagId = t2.id) as [Total count], t1.TagName [Singular name], ( select count(*) AS cnts from posttags pts where pts.TagId = t1.id) as [Singular count], t2.TagName [Plural tag], ( select count(*) AS cntp from posttags ptp where ptp.TagId = t2.id) as [Plural count] from Tags t1 join Tags t2 on ( t1.TagName + 's' = t2.TagName) order by [Total count] desc
2010-06-08 21:51:19
false
2,667
Most common tags with singular and plural version (es-plural)
Tags which that have singular and plural version (with es-plural). For example [hash] and [hashes].
WITH singular and plural version (es-plural) -- Tags which that have singular and plural version (WITH es-plural). -- For example [hash] and [hashes]. select ( select count(*) AS cnts from posttags pts where pts.TagId = t1.id) + ( select count(*) AS cnts from posttags pts where pts.TagId = t2.id) as [Total count], t1.TagName [Singular name], ( select count(*) AS cnts from posttags pts where pts.TagId = t1.id) as [Singular count], t2.TagName [Plural tag], ( select count(*) AS cntp from posttags ptp where ptp.TagId = t2.id) as [Plural count] from Tags t1 join Tags t2 on ( t1.TagName + 'es' = t2.TagName) order by [Total count] desc
2010-06-08 22:00:13
false
2,680
Users with high self-accept rates (and having > 10 answe
(the extreme self-learners)
WITH high self-accept rates (and having > 10 answe -- (the extreme self-learners) SELECT TOP 100 Users.Id AS [User Link], ROUND((CAST(Count(a.Id) AS float) / CAST((SELECT Count(*) FROM Posts p WHERE p.OwnerUserId = Users.Id AND PostTypeId = 1) AS float) * 100),2) AS SelfAnswerPercentage FROM Posts q INNER JOIN Posts a ON q.AcceptedAnswerId = a.Id INNER JOIN Users ON Users.Id = q.OwnerUserId WHERE q.OwnerUserId = a.OwnerUserId GROUP BY Users.Id, DisplayName HAVING Count(a.Id) > 10 ORDER BY SelfAnswerPercentage DESC
2010-06-09 06:03:08
false
2,735
Users ranked by badge per day
null
DECLARE @endDate date SELECT @endDate = max(CreationDate) from Posts SELECT TOP 100 *, CONVERT(float, NumBadges)/Days as [BadgePerDay] FROM ( SELECT Users.Id as [User Link], COUNT(*) as [NumBadges], MAX(DateDiff(Day, Users.CreationDate, @endDate)) as [Days] FROM Users INNER JOIN Badges ON Users.Id = Badges.UserId GROUP BY Users.Id ) as UsersWithBadgeCount WHERE Days > 30 ORDER BY BadgePerDay DESC
2010-06-09 22:34:05
false
2,765
Recent Tab Works - You Just Have to save a query for it to show up here
It works
SELECT 'waffles keeps on changing stuff here, and will be adding a spy tab where you can see everything'
2019-07-07 11:02:38
false
2,777
Users by Popular Question ratio
(only users with at least 10 Popular Questions)
SELECT num.TagName as Tag, row_number() over (order by rate.Rate desc) as SeptemberRank, row_number() over (order by num.Num desc) as TotalRank, rate.Rate as QuestionsInMay, num.Num as QuestionsTotal from (SELECT count(PostId) as Rate, TagName from Tags, PostTags, Posts where Tags.Id = PostTags.TagId and Posts.Id = PostId and Posts.CreationDate < '2019-09-01' and Posts.CreationDate > '2019-08-01' group by TagName) as rate INNER JOIN (SELECT count(PostId) as Num, TagName from Tags, PostTags, Posts where Tags.Id = PostTags.TagId and Posts.Id = PostId group by TagName having count(PostId) > 800) as num ON rate.TagName = num.TagName order by rate.rate desc ;
2020-10-08 15:43:37
false
2,803
Users by location, with a minimum reputation
null
WITH a minimum reputation select Id as "User Link", Reputation, WebsiteUrl as "Website URL", Location from Users where Location like '%##location##%' and Reputation >= ##minimumReputation## order by Reputation desc
2020-12-09 04:38:29
false
2,868
How high would my reputation approximately be when there was no cap or CW?
null
DECLARE @UserId int = ##UserId## SELECT SUM(CASE WHEN VoteTypeId = 1 THEN 15 -- Accepted answer. WHEN VoteTypeId = 2 AND PostTypeId = 1 THEN 10 -- Upvoted question WHEN VoteTypeId = 2 AND PostTypeId = 2 THEN 10 -- Upvoted answer. WHEN VoteTypeId = 3 THEN -2 -- Downvote. WHEN VoteTypeId = 9 THEN BountyAmount -- Earned Bounty END) AS UncappedReputation FROM Votes INNER JOIN Posts ON Posts.Id = Votes.PostId WHERE Posts.OwnerUserId = @UserId
2020-06-19 17:33:23
false
3,335
Possible editors for the 'rebol' tag
Lists every user who has ever answered a question on the 'rebol' tag, along with if they have sufficient rep to edit questions
WITH if they have sufficient rep to edit questions SELECT MAX(Users.Reputation), Users.Id AS [User Link], [Can edit] = CASE WHEN MAX(Users.Reputation) >= 2000 THEN 'yes' ELSE 'no' END FROM Posts, Users, PostTags, Tags WHERE Posts.OwnerUserId = Users.Id AND Posts.ParentId = PostTags.PostId AND PostTags.TagId = Tags.Id AND Tags.TagName = 'rebol' GROUP BY Users.Id ORDER BY MAX(Reputation) DESC;
2010-06-14 18:37:40
false
3,499
Most popular replies to my comments
Shows the highest-scoring comments to include "@yourname". Of course, people can reply to you with only part of your username, and your username can change, and other users can have the same name as you, so it's not 100% accurate.
WITH only part of your username, and your username can change, -- and other users can have the same name as you, so it's not 100% accurate. SELECT TOP 100 Comments.PostId AS [Post Link], Users.DisplayName, Comments.Score, Comments.Text, Comments.CreationDate FROM Comments LEFT JOIN Users on Comments.UserID = Users.ID WHERE Comments.Text LIKE '%@##UserName##%' ORDER BY Comments.score DESC
2010-06-15 00:36:26
false
3,631
List of Users in a given location
This query lists all users in a given location sorted by reputation.
SELECT * FROM Users WHERE Location LIKE '%##location##%' ORDER BY CreationDate ASC
2020-04-17 03:04:42
false
3,773
My top comments (eligible for Pundit badge)
Show comments with 10 or more upvotes
WITH 10 or more upvotes select row_number() over(order by score asc) as rownum, postid as [Post Link], score, text from comments where userid = ##userid## order by score desc
2012-01-22 15:14:13
false
3,938
How many upvotes do I have for each tag? (Wiki & Non-Wiki)
how long before I get tag badges?
DECLARE @UserId int = ##UserId## SELECT --TOP 20 TagName, SUM(CASE WHEN Posts.CommunityOwnedDate IS NULL OR Votes.CreationDate < Posts.CommunityOwnedDate THEN 1 ELSE 0 END) AS NonWikiUpvotes, COUNT(*) AS UpVotes FROM Tags INNER JOIN PostTags ON PostTags.TagId = Tags.id INNER JOIN Posts ON Posts.ParentId = PostTags.PostId INNER JOIN Votes ON Votes.PostId = Posts.Id and VoteTypeId = 2 WHERE Posts.OwnerUserId = @UserId GROUP BY TagName ORDER BY UpVotes DESC
2010-06-16 18:36:19
false
3,978
Most popular StackOverflow tags in May 2010
null
SELECT num.TagName as Tag, row_number() over (order by rate.Rate desc) as MayRank, row_number() over (order by num.Num desc) as TotalRank, rate.Rate as QuestionsInMay, num.Num as QuestionsTotal from (SELECT count(PostId) as Rate, TagName from Tags, PostTags, Posts where Tags.Id = PostTags.TagId and Posts.Id = PostId and Posts.CreationDate < '2010-06-01' and Posts.CreationDate > '2010-05-01' group by TagName) as rate INNER JOIN (SELECT count(PostId) as Num, TagName from Tags, PostTags, Posts where Tags.Id = PostTags.TagId and Posts.Id = PostId group by TagName having count(PostId) > 800) as num ON rate.TagName = num.TagName order by rate.rate desc ;
2020-12-03 11:46:10
false
3,981
StackOverflow topics in May 2010
It would be nice to have a graph, I know :)
SELECT num.TagName as Topic, row_number() over (order by rate.Rate desc) as MayRank, row_number() over (order by num.Num desc) as TotalRank, rate.Rate as QuestionsInMay, num.Num as QuestionsTotal from (SELECT count(PostId) as Rate, TagName from Tags, PostTags, Posts where Tags.Id = PostTags.TagId and Posts.Id = PostId and Posts.CreationDate < '2010-06-01' and Posts.CreationDate > '2010-05-01' group by TagName) as rate INNER JOIN (SELECT count(PostId) as Num, TagName from Tags, PostTags, Posts where Tags.Id = PostTags.TagId and Posts.Id = PostId group by TagName having count(PostId) > 800) as num ON rate.TagName = num.TagName order by rate.rate desc ;
2010-06-17 01:29:54
false
4,272
Top n posters for a given country
Gets the top n poster for a country of your choice
DECLARE @TopCount INT = ##TopCount## SELECT TOP (@TopCount) Id, DisplayName, reputation, LastAccessDate, Age, Location FROM Users WHERE Location LIKE '##COuntry##%' ORDER BY Reputation DESC
2010-06-18 10:41:41
false
4,608
Question where my answer has been accepted but some answer has better score than mine
This query will return, for a user, the list of question where his answer has been accepted but some others answer has better score
SELECT Q.id as Qid, Q.title as Qtitle, myA.id as myAid, myA.Body as myAbody, allA.id as OthersAid, allA.Body as OthersAbody FROM Posts myA, Posts allA, Posts Q WHERE Q.id=allA.ParentId AND Q.AcceptedAnswerId=myA.id AND myA.OwnerUserId = ##UserId## AND myA.PostTypeId = 2 AND allA.PostTypeId = 2 AND allA.score > myA.score
2010-06-20 17:23:04
false
4,797
What is my reputation's percentile?
Computes what percentage of users have lower reputation than the given user ID. A minimum reputation can be specified to cut off one-time users and other such outliers. (use a large negative number to consider all users)
WITH Population(TotalUsers, UsersBelowMe) AS ( SELECT SUM(CASE WHEN uAll.Reputation > ##MinReputation## THEN 1 ELSE 0 END) AS TotalUsers, SUM(CASE WHEN uAll.Reputation < uMe.Reputation AND uAll.Reputation > ##MinReputation## THEN 1 ELSE 0 END) AS UsersBelowMe FROM Users uMe CROSS JOIN Users uAll WHERE uMe.Id = ##UserId##) SELECT 100.0 * UsersBelowMe / TotalUsers AS Percentile, UsersBelowMe, TotalUsers FROM Population
2013-12-31 02:41:48
false
4,850
Number of users with less or equal to X rep
49% of users on Stack Overflow have 1 rep. Wow!
DECLARE @LessThanX float select @LessThanX = count(*) from users where reputation >= ##X## DECLARE @AllUsers float select @AllUsers = count(*) from users select @LessThanX
2017-05-15 17:58:44
false
5,289
How many upvotes do I have for each tag (Silver and Gold)?
how long before I get tag badges?
DECLARE @UserId int = ##UserId## SELECT --TOP 20 TagName, 400 - COUNT(*) AS 'UpVotes to Silver', 1000 - COUNT(*) AS 'UpVotes to Gold' FROM Tags INNER JOIN PostTags ON PostTags.TagId = Tags.id INNER JOIN Posts ON Posts.ParentId = PostTags.PostId INNER JOIN Votes ON Votes.PostId = Posts.Id and VoteTypeId = 2 WHERE Posts.OwnerUserId = @UserId GROUP BY TagName ORDER BY 'UpVotes to Silver'
2010-06-25 15:21:37
false
5,465
Testing WITH CUBE (and ROLLUP)
It seems even though you cannot refer to column names in normal SQL (simple ORDER BY references excepted -- a SQL Extension I believe) you do have to consider the matching expression as a name because although ISNULL(x,y) should never be null, it clearly is in the subtotal for that row.
DECLARE @UserId int = ##UserId## SELECT datepart(year,creationdate) as [Year], datepart(month,creationdate) as [Date], ISNULL(Score,-1) AS [Score], Count(*) AS CommentCount, Sum(Len(Text)) As Typed FROM Comments WHERE UserId = @UserId GROUP BY datepart(year,creationdate), datepart(month,creationdate), ISNULL(Score,-1) WITH cube ORDER BY ISNULL(datepart(year,creationdate),9999), ISNULL(datepart(month,creationdate),13), ISNULL(ISNULL(Score,-1),-2) DESC, CommentCount Desc
2010-06-26 10:56:57
false
5,473
Testing CUBE (and ROLLUP) using ISO-Compliant syntax
It seems even though you cannot refer to column names in normal SQL (simple ORDER BY references excepted -- a SQL Extension I believe) you do have to consider the matching expression as a name because although ISNULL(x,y) should never be null, it clearly is in the subtotal for that row. But you can also use the Grouping() expression and this seems to be its main reason for existing.
DECLARE @UserId int = ##UserId## SELECT datepart(year,creationdate) as [Year], datepart(month,creationdate) as [Date], Score AS [Score], Count(*) AS CommentCount, Sum(Len(Text)) As Typed, Grouping(datepart(year,creationdate)), Grouping(datepart(month,creationdate)), Grouping(Score) FROM Comments WHERE UserId = @UserId GROUP BY CUBE(datepart(year,creationdate), datepart(month,creationdate), Score) ORDER BY ISNULL(datepart(year,creationdate),9999), ISNULL(datepart(month,creationdate),13), ISNULL(Score,CASE WHEN Grouping(Score)=0 THEN -1 ELSE -2 END) DESC, CommentCount Desc
2010-06-26 11:39:44
false
5,486
Users with the most rep-gaining answer acceptances
SELECT TOP 100 u.Id AS [User Link], u.Reputation, ( SELECT COUNT(*) FROM Posts q WHERE q.OwnerUserId = u.Id AND q.PostTypeId = 1 ) AS 'All Questions', ( SELECT COUNT(*) FROM Votes v INNER JOIN Posts a ON a.Id = v.PostId INNER JOIN Posts q ON q.Id = a.ParentId WHERE q.OwnerUserId = u.Id AND v.VoteTypeId = 1 AND q.OwnerUserId != a.OwnerUserId AND (q.CommunityOwnedDate IS NULL OR q.CommunityOwnedDate > v.CreationDate) ) AS 'Rep-gaining Acceptances' FROM Users u ORDER BY 'Rep-gaining Acceptances' DESC
2010-06-26 20:37:53
false
5,530
High Score Questions Without Accepted Answer by Reputable Users
Find useful questions by users who are respected in the community.
WITH out Accepted Answer by Reputable Users -- Find useful questions by users who are respected in the community. SELECT Posts.Id AS [Post Link], Posts.Score AS [Score], Posts.ViewCount AS [View Count], Users.Reputation AS [Asker Rep] FROM Posts INNER JOIN PostTags ON Posts.Id = PostTags.PostId INNER JOIN Tags ON PostTags.TagId = Tags.id INNER JOIN Users ON Users.Id = Posts.OwnerUserId WHERE Posts.ClosedDate is NULL AND Posts.CommunityOwnedDate is NULL AND Posts.AcceptedAnswerId is NULL AND Posts.Score >= ##MinPostScore## AND Users.Reputation >= ##MinAskerRep## ORDER BY Posts.Score DESC, Posts.ViewCount DESC
2014-12-12 18:53:10
false
5,646
#Temporary tables, indexes and procedures work!
#Temporary views and functions return errors stating they're not allowed. Use Text-only results, and include the execution plan to see the index has been used.
SELECT * from tags
2014-05-14 01:25:24
false
6,134
Total Questions and Answers per Month for the last 12
Total number of questions and answers for the last 12 months (in 30 day chunks)
SELECT count(Id) FROM Posts WHERE ParentId is null and CreationDate >= '2014/11/01' and CreationDate < '2014/12/01' and Tags like '%google-cast%';
2015-07-25 00:25:36
false
6,193
Find Stack Overflow Users In Your City
A simply query to find users in your city or country.
SELECT Id,Reputation,DisplayName FROM Users WHERE Location LIKE '%##Location##%' ORDER BY Reputation DESC
2016-03-24 16:39:00
false
6,559
Number of Qs and As per month
null
SELECT month(CreationDate) as month, year(CreationDate) as year, (SELECT count(id) from Posts where PostTypeId=1 and (month(CreationDate) = month(p1.CreationDate)and year(CreationDate) = year(p1.CreationDate))) as questions, (SELECT count(id) from Posts where PostTypeId=2 and (month(CreationDate) = month(p1.CreationDate)and year(CreationDate) = year(p1.CreationDate))) as answers, count(Id) as total from Posts as p1 group by month(CreationDate), year(CreationDate) order by year desc, month desc
2010-07-07 23:14:14
false
6,582
How many non-CW upvotes do I have for each tag?
Shows the totals of non community wiki upvotes in each tag
DECLARE @UserId int = ##UserId## SELECT --TOP 20 TagName, COUNT(*) AS UpVotes FROM Tags INNER JOIN PostTags ON PostTags.TagId = Tags.id INNER JOIN Posts ON Posts.ParentId = PostTags.PostId INNER JOIN Votes ON Votes.PostId = Posts.Id and VoteTypeId = 2 WHERE Posts.OwnerUserId = @UserID AND (Votes.CreationDate < Posts.CommunityOwnedDate OR Posts.CommunityOwnedDate IS NULL) GROUP BY TagName ORDER BY UpVotes DESC
2010-07-08 02:13:08
false
6,651
Question rep vs Answer rep
My scores from questions and answers
SELECT case when p.PostTypeId = 1 then 'Question' else 'Answer' end as 'Post Type', case when p.PostTypeId = 1 then SUM(p.Score) * 5 when p.PostTypeId = 2 then SUM(p.Score) * 10 end as 'Score' FROM Posts p WHERE p.OwnerUserId = 31716 GROUP BY p.PostTypeId
2016-07-22 23:58:30
false
6,709
find number of questions for a list of tags
given a list of tags find out how many question each of the tags has
SELECT Tags.Tagname, count(Posts.Id) as questions, sum(ViewCount) as views from Posts left join PostTags on PostS.Id = PostTags.PostId left Join Tags on PostTags.TagId = Tags.Id where Tags.TagName in ( -- enter tags here 'asterisk', 'pbx', 'sms', 'voip' ) group by Tags.TagName
2010-07-08 22:55:32
false
6,710
questions + views for tags on serverfault
Enter Query Description
SELECT Tags.Tagname, count(Posts.Id) as questions, sum(ViewCount) as views from Posts left join PostTags on PostS.Id = PostTags.PostId left Join Tags on PostTags.TagId = Tags.Id where Tags.TagName in ( -- enter tags here 'asterisk', 'pbx', 'sms', 'voip' ) group by Tags.TagName
2010-07-08 22:57:00
false
6,803
How do I Rank Compared to Other Users
What is my overall rank compared to other users and which user page am I on.
DECLARE @UserId int = ##UserId## select (count(*) + 1) as Rank, ((count(*) / 35) + 1) 'User Page', (select reputation from users where id = @UserId) Reputation from users where reputation > (select u.reputation from users u where u.id = @UserId)
2010-07-09 16:30:12
false
6,856
High Standards - Top 100 Users that rarely upvote.
Top 100 Users that rarely upvote in comparison to the estimated amount of upvotes they received (doesn't account for e.g. bounties but should give a sufficient estimation). Useful settings (MinRep, MinUpvotes): (1000, 100), (10000, 0).
SELECT TOP 1000 posts.id, body, tagid, tagname from posts inner join posttags on posts.id = posttags.postid inner join tags on posttags.tagid = tags.id where tagname in ('javascript', 'jquery', 'java', 'c#') order by posts.id
2020-01-29 20:28:52
false
7,074
Posts with many "thank you" answers, ordered by views
Looking at posts shorter than 200 with the text `thank` somewhere in it, ordered by views
WITH many "thank you" answers, ordered by views -- Looking at posts shorter than 200 WITH the text `thank` somewhere in it, ordered by views select a.ParentId as [Post Link], count(a.id), sum(q.ViewCount) / count(a.id) from posts a inner join posts q on a.ParentId = q.Id where q.posttypeid = 1 and a.posttypeid = 2 and len(a.body) <= 200 and (a.body like '%thank%') group by a.ParentId having count(a.Id) > 1 order by count(a.Id) desc, sum(q.ViewCount) desc
2010-07-13 03:57:54
false
7,147
Unanswered Inactive Questions for a Specific Tag
Inactive questions with no answers for a specific tag (ViewCount ASC)
WITH No Answers for a Specific Tag -- Inactive questions WITH no answers for a specific tag (ViewCount ASC) SELECT TOP 100 Id AS [Post Link], Tags, ViewCount, CreationDate FROM Posts WHERE ParentId IS NULL AND AnswerCount = 0 AND Tags LIKE '<batch-file>' ORDER BY ViewCount ASC
2017-10-06 12:29:26
false
7,172
My edits - S&W and Copy Editor
Approximate number of edits performed.
DECLARE @user int = ##userid##; select count(p.id) as 'Edits' from posts p where p.owneruserid != @user and p.lasteditoruserid = @user;
2010-07-13 16:11:21
false
7,245
Check Strunk und White process
Return how far I have to go to get S&W
DECLARE @UserId int = 3038 SELECT 100 - COUNT(*) AS 'Edits To Strunk & White' FROM Posts WHERE PostTypeId = 1 AND LastEditorUserId = @UserId AND OwnerUserId != @UserId
2019-07-20 13:05:06
false
7,296
Count Users with X Reputation or Higher
This query does a simple count of all users in the database with the specified minimum reputation.
WITH X Reputation or Higher -- This query does a simple count of all users in the database WITH the specified minimum reputation. SELECT Count = COUNT(*) FROM Users WHERE Reputation >= '##reputation##'
2010-07-14 01:14:29
false
7,570
Users in Location including active tags, sorted by Rep.
Users in Location including active tags, sorted by Rep.
SELECT Id AS [User Link], Reputation, WebsiteUrl, Age, LastAccessDate, Tags = ( SELECT TOP 3 TagName FROM Tags INNER JOIN PostTags ON PostTags.TagId = Tags.id INNER JOIN Posts ON Posts.ParentId = PostTags.PostId INNER JOIN Votes ON Votes.PostId = Posts.Id and VoteTypeId = 2 WHERE Posts.OwnerUserId = U.ID GROUP BY TagName ORDER BY COUNT(*) DESC FOR XML PATH('') ) FROM Users U WHERE Location LIKE '%' + ##Location:string## + '%' ORDER BY Reputation DESC
2010-07-18 15:47:28
false
7,672
Bounties and Questions by Month
Computes the number of bounties awarded and the total bounty amount awarded each month, along with the number of questions asked.
SELECT * from information_schema.tables
2020-03-09 03:01:27
false
7,735
Users sorted by average score.
Votes per answer (non-CW, with at least 100 answers to their credit)
WITH at least 100 answers to their credit) select u.id as [User Link], u.reputation as 'Rep', count(a.id) as 'Answers', sum(a.score) as 'Total Score', cast (sum(a.score) as float) / cast(count(a.id) as float) as 'Average' from posts a, users u where a.owneruserid = u.id and a.posttypeid = 2 and a.communityowneddate is null group by u.id, u.reputation having count(a.id) > 400 order by cast (sum(a.score) as float) / cast(count(a.id) as float) asc
2013-03-07 06:12:20
false
7,802
Posts with many "thank you" answers -- yet no accepted answer
null
SELECT p.ParentId as [Post Link], count(p.id) from posts p inner join posts as parent on parent.id=p.parentId where p.posttypeid = 2 and len(p.body) <= 200 and (p.body like '%hank%') and parent.AcceptedAnswerId is null group by p.parentid having count(p.id) > 1 order by count(p.id) desc;
2010-07-21 00:14:10
false
7,885
A user's posts, non-paged (non-Community Wiki)
A way around paging for a user's posts, questions and answers. A view count of zero means it is an answer.
SELECT p.Id as [Post Link], Score as [Votes], ViewCount as [Views], p.CommunityOwnedDate as [CW] FROM Posts p WHERE p.OwnerUserId = ##UserId## AND p.CommunityOwnedDate is null -- Field CommunityOwnedDate is absent for non-CW posts. ORDER BY ViewCount DESC
2010-07-21 03:43:16
false
7,888
Highest Voted Posts (non-Community Wiki)
Non-CW posts with the highest number of votes. If views is zero then it is an answer.
WITH the highest number of votes. If views is zero then it is an answer. SELECT TOP 100 p.Id as [Post Link], Score as [Votes], ViewCount as [Views] FROM Posts p WHERE p.CommunityOwnedDate is not null AND -- Field CommunityOwnedDate is absent for non-CW posts. p.OwnerUserId = ##UserId## ORDER BY Score DESC
2018-08-15 00:42:28
false
8,030
Strunk & White and Copy Editor Progress
Counts the number of edits a user has made.
DECLARE @UserId int = ##UserId## SELECT COUNT(*) FROM Posts WHERE PostTypeId = 1 AND LastEditorUserId = @UserId AND OwnerUserId != @UserId
2010-07-23 12:54:27
false
8,105
Show the hours of the day a user is most active
Gets the hours in which a user has been active (enables you to see when a user sleeps!)
WITH hours as ( select datepart(hh, creationdate) as HoursSeen from posts where owneruserid = ##UserId## union all select datepart(hh, creationdate) as HoursSeen from comments where userid = ##UserId## ) select HoursSeen as Hour, count(*) as Count, '|' + replicate('*', count(*)) as Graph from hours group by HoursSeen order by HoursSeen
2010-07-25 02:58:12
false
8,153
Worst Case Scenario, How Long Until the Electorate Badge
These data dumps do not include how many questions I have voted up or down. So Assuming that none of the votes I have given are for questions, how many days voting on 30 questions per day do I have until I get the Electorate badge.
DECLARE @UserId int = ##UserId## DECLARE @voteCount int select @voteCount = u.UpVotes + u.DownVotes from Users u where u.Id = @UserId -- using equivalent of max function given by this answer: http://stackoverflow.com/questions/293804 -- this is used to determine the max days when less than 600 total votes -- This will give the maximum of 5 days or the amount of days to reach 600 select @voteCount as TotalVotes, case when @voteCount < 600 then ceiling(0.5 * ((600 - @voteCount)/30.0 + 5) + ((600 - @voteCount)/30.0 - 5)) when exists(select 1 from Badges where UserId = @UserId and Name = 'Electorate') then 0 else ceiling(@voteCount / (4 * 30.0)) end as MaxDaysUntilElectorate
2020-07-03 12:58:04
false
8,164
Amount of Bounties for Each Bounty Amount
Shows all bounty values and the amount of bounties for each bounty amount.
SELECT BountyAmount, count(*) AmountOfBounties from Votes where BountyAmount is not null and BountyAmount > 0 group by BountyAmount order by BountyAmount desc
2010-07-25 13:00:03
false
8,196
Questions I have answered where asker has not accepted an answer
Lists all questions I have proposed an answer to, but the original question asker hasn't accepted an answer
SELECT p.Id AS [Post Link], p.AnswerCount FROM Posts a, Posts p WHERE a.OwnerUserId = ##UserId## AND a.PostTypeId = 2 AND p.AcceptedAnswerId IS NOT NULL AND p.Id = a.ParentId ORDER BY p.AnswerCount DESC
2017-12-15 04:28:26
false
8,201
What tag wikis can I edit?
List all tags you have a score of 100 for. You also need 2,000 reputation. Remember: tag wikis are located on the tag page under the info tab.
DECLARE @UserId int = ##UserId## SELECT TagName as "You can edit the following tag wikis" FROM Tags INNER JOIN PostTags ON PostTags.TagId = Tags.id INNER JOIN Posts ON Posts.ParentId = PostTags.PostId INNER JOIN Votes ON Votes.PostId = Posts.Id and VoteTypeId = 2 WHERE Posts.OwnerUserId = @UserId GROUP BY TagName HAVING count(*) >= 10 ORDER BY TagName DESC
2016-03-30 01:14:16
false
8,265
What tag wikis can I edit? (Corrected to exclude CW posts)
List all tags you have 100 upvotes for. (Excludes CW posts) Remember: tag wikis are located on the tag page under the info tab.
DECLARE @UserId int = ##UserId## SELECT TagName as "You can edit the following tag wikis" FROM Tags INNER JOIN PostTags ON PostTags.TagId = Tags.id INNER JOIN Posts ON Posts.ParentId = PostTags.PostId INNER JOIN Votes ON Votes.PostId = Posts.Id and VoteTypeId = 2 WHERE Posts.OwnerUserId = @UserId AND Posts.CommunityOwnedDate is null GROUP BY TagName HAVING count(*) >= 100 ORDER BY TagName DESC
2010-07-27 16:33:09
false
8,384
Users Answer and Question Votes
See the total up and down votes for answers and questions for a given user.
DECLARE @userid int = ##UserID## select (case when p.posttypeid = 1 then 'Question' when p.posttypeid = 2 then 'Answer' end) as [Post Type], (case when v.votetypeid = 2 then 'Up Vote' when v.votetypeid = 3 then 'Down Vote' end) as [Vote Type], count(*) As Votes from votes v join posts p on v.postid = p.id where v.votetypeid in (2,3) and v.userid = @userid group by p.posttypeid, v.votetypeid
2013-09-07 19:21:24
false
8,394
Questions by Tag and Minimum Asker Reputation
Show all questions with the specified tag where the question's asker has at least the specified reputation
WITH the specified tag where the question's asker has at least the specified reputation SELECT Posts.Id AS [Post Link], Posts.CreationDate, Users.ID AS [User Link], Users.Reputation FROM Posts, Users /*WHERE Posts.Id = PostTags.PostId AND PostTags.TagId = Tags.Id AND Tags.TagName = '##TagName##' */ WHERE Posts.OwnerUserId = Users.Id AND Users.Reputation >= ##MinReputation## ORDER BY CreationDate DESC;
2012-02-03 06:59:47
false
8,479
Which users have the most favourites?
null
SELECT count(v.Id) as UserFaves, u.Reputation from Users u inner Join Votes v on v.UserId = u.Id and v.VoteTypeId = 5 group by u.Id, u.Reputation order by UserFaves desc
2010-07-29 04:42:56
false
8,553
How many edits do I have?
Counts how many edits a user has, broken into Question and Answer edits. Also shows how close you are to getting each editor badge.
WITH qaedits AS ( SELECT ( SELECT COUNT(*) FROM Posts WHERE PostTypeId = 1 AND LastEditorUserId = Users.Id ) AS QuestionEdits, ( SELECT COUNT(*) FROM Posts WHERE PostTypeId = 2 AND LastEditorUserId = Users.Id ) AS AnswerEdits FROM Users WHERE Id = ##UserId## ), edits AS ( SELECT QuestionEdits, AnswerEdits, QuestionEdits + AnswerEdits AS TotalEdits FROM qaedits ) SELECT QuestionEdits, AnswerEdits, TotalEdits, CASE WHEN TotalEdits >= 1 THEN 'Received' ELSE '0%' END AS EditorBadge, CASE WHEN TotalEdits >= 80 THEN 'Received' ELSE Cast(TotalEdits AS varchar) + '%' END AS StrunkAndWhiteBadge, CASE WHEN TotalEdits >= 500 THEN 'Received' ELSE Cast(TotalEdits / 5 AS varchar) + '%' END AS CopyEditorBadge FROM edits
2015-02-24 09:18:08
false
8,782
Users who post long answers
Statistical summary of users who like to post long answers. Filters for users above a minimal post count.
SELECT TOP 2000 Rank = Row_Number() OVER (ORDER BY avg(len(p.Body)) DESC), UserId = p.OwnerUserId, Username = Min(u.DisplayName), Total_Posts = Count(*), Average_Length_Of_Posts = avg(len(p.Body)), Total_Length_Of_Posts = sum(len(p.Body)), Longest_Post = max(len(p.Body)), Standard_Deviation_Of_Post_Lengths = stdev(len(p.Body)), Total_Rep = Min(u.Reputation), Rep_Per_Character = Min(Convert(float, u.Reputation)) / sum(len(p.Body)) FROM Posts p INNER JOIN Users u ON u.Id = p.OwnerUserId WHERE p.PostTypeId = 2 and u.Id=1094246 GROUP BY p.OwnerUserId HAVING Count(*) >= ##MinimumPostCount##
2018-07-21 11:54:44
false
9,000
Up vs Down votes by day of week of Accepted Answer
null
SELECT DATENAME(WEEKDAY, p.CreationDate) AS Day, Count(*) AS Amount, SUM(CASE WHEN VoteTypeId = 2 THEN 1 ELSE 0 END) AS UpVotes, SUM(CASE WHEN VoteTypeId = 3 THEN 1 ELSE 0 END) AS DownVotes, (CAST(SUM(CASE WHEN VoteTypeId = 2 THEN 1 ELSE 0 END) AS float) / CAST(SUM(CASE WHEN VoteTypeId = 3 THEN 1 ELSE 0 END) AS float)) AS UpVoteDownVoteRatio FROM Votes v JOIN Posts p ON v.PostId=p.AcceptedAnswerId WHERE PostTypeId=1 AND p.AcceptedAnswerId IS NOT NULL AND VoteTypeId In (2,3) GROUP BY DATEPART(WEEKDAY, p.CreationDate), DATENAME(WEEKDAY, p.CreationDate) ORDER BY DATEPART(WEEKDAY, p.CreationDate)
2012-05-10 21:11:02
false
9,001
Up vs Down votes by hour of day of Accepted Answer
null
SELECT DATEPART(HOUR, p.CreationDate) AS Hour, Count(*) AS Amount, SUM(CASE WHEN VoteTypeId = 2 THEN 1 ELSE 0 END) AS UpVotes, SUM(CASE WHEN VoteTypeId = 3 THEN 1 ELSE 0 END) AS DownVotes, (CAST(SUM(CASE WHEN VoteTypeId = 2 THEN 1 ELSE 0 END) AS float) / CAST(SUM(CASE WHEN VoteTypeId = 3 THEN 1 ELSE 0 END) AS float)) AS UpVoteDownVoteRatio FROM Votes v JOIN Posts p ON v.PostId=p.AcceptedAnswerId WHERE PostTypeId = 1 AND AcceptedAnswerId IS NOT NULL GROUP BY DATEPART(HOUR, p.CreationDate) ORDER BY DATEPART(HOUR, p.CreationDate)
2010-08-04 15:39:16
false
9,003
Up vs Down votes by hour of week of Accepted Answer
null
SELECT DATENAME(WEEKDAY, p.CreationDate) AS [Day], DATEPART(HOUR, p.CreationDate) AS [Hour], Count(*) AS Amount, SUM(CASE WHEN VoteTypeId = 2 THEN 1 ELSE 0 END) AS UpVotes, SUM(CASE WHEN VoteTypeId = 3 THEN 1 ELSE 0 END) AS DownVotes, (CAST(SUM(CASE WHEN VoteTypeId = 2 THEN 1 ELSE 0 END) AS float) / CAST(SUM(CASE WHEN VoteTypeId = 3 THEN 1 ELSE 0 END) AS float)) AS UpVoteDownVoteRatio FROM Votes v JOIN Posts p ON v.PostId=p.AcceptedAnswerId WHERE PostTypeId = 1 AND AcceptedAnswerId IS NOT NULL GROUP BY PostTypeId, DATEPART(WEEKDAY, p.CreationDate), DATENAME(WEEKDAY, p.CreationDate), DATEPART(HOUR, p.CreationDate) ORDER BY PostTypeId, --DATEPART(WEEKDAY, p.CreationDate), DATEPART(HOUR, p.CreationDate) 6
2010-08-04 15:56:59
false
9,118
Tags: Spelling variants (AE/BE: o/ou)
null
WITH PostCounts as ( select Tags.Id as TagId, count(Posts.Id) as PostCount from Posts inner join PostTags on Posts.Id = PostTags.PostId inner join Tags on PostTags.TagId = Tags.Id group by Tags.Id ), Variants as ( select * from (select replace(TagName, 'ou', 'o') as vname, * from tags) as r where vname != tagname ) select Tags.TagName, tc.PostCount, Variants.TagName, vc.PostCount from Tags inner join Variants on Tags.tagName = Variants.vname inner join PostCounts tc on Tags.Id = tc.TagId inner join PostCounts vc on Variants.Id = vc.TagId order by vc.PostCount desc;
2010-08-08 19:28:42
false
9,119
Tags: Spelling variants (AE/BE: z/s)
null
WITH PostCounts as ( select Tags.Id as TagId, count(Posts.Id) as PostCount from Posts inner join PostTags on Posts.Id = PostTags.PostId inner join Tags on PostTags.TagId = Tags.Id group by Tags.Id ), Variants as ( select * from (select replace(TagName, 's', 'z') as vname, * from tags) as r where vname != tagname ) select Tags.TagName, tc.PostCount, Variants.TagName, vc.PostCount from Tags inner join Variants on Tags.tagName = Variants.vname inner join PostCounts tc on Tags.Id = tc.TagId inner join PostCounts vc on Variants.Id = vc.TagId order by vc.PostCount desc;
2010-08-08 20:36:31
false
9,300
Query for Nerd Dinner Prospects!
Users with certain minimum requirements!
WITH certain minimum requirements! select Id as "User Link", Reputation,LastAccessDate, WebsiteUrl as "Website URL", Age , Location, AboutMe as "About me" from Users where Location like '%##location##%' and Reputation >= ##minimumReputation## and Age <= ##age## order by LastAccessDate desc
2010-08-12 23:45:01
false
9,320
Find Stack Overflow Users In Your City (with user-links)
A simply query to find users in your city or country. Added user links to the original version.
WITH user-links) -- A simply query to find users in your city or country. Added user links. select Id [User Link], Reputation, DisplayName, Location from Users where Location like '%##Location##%' order by Reputation desc
2020-11-29 23:44:33
false
9,412
Users with '.com' in their display name
null
WITH '.com' in their display name SELECT Id AS [User Link] FROM Users WHERE DisplayName LIKE '%.com'
2020-07-18 22:23:00
false
9,643
RANK, parition by id order by value_type
null
WITH test AS ( SELECT 1 AS id, 'B' AS value_type UNION ALL SELECT 1, 'B' UNION ALL SELECT 1, 'A' UNION ALL SELECT 2, 'A' UNION ALL SELECT 2, 'A'), summary AS ( SELECT t.*, RANK() OVER (PARTITION BY t.id ORDER BY t.value_type DESC) AS rank FROM test t) SELECT * FROM summary WHERe rank = 1
2010-08-21 01:19:17
false
9,849
Top 100 users by average normalized score
Users who have the highest share in total score received by all answers to the questions they answered (among users with >100 eligible answers, includes answers with score >=0 and questions with total score of answers >0)
SELECT TOP 100 u.Id as [User Link], AVG(a.NormalizedScore) as AvgNormalizedScore FROM Users u JOIN (SELECT (CAST(a.Score AS float) / SUM(allA.Score)) * 100 AS NormalizedScore, a.Id, a.OwnerUserId FROM Posts a JOIN Posts q ON a.ParentId = q.Id JOIN Posts allA ON allA.ParentId = q.Id WHERE a.PostTypeId = 2 and a.Score >= 0 and allA.score > 0 GROUP BY a.Id, a.OwnerUserId, a.Score HAVING SUM(allA.Score) > 0) a ON a.OwnerUserId = u.Id GROUP BY u.Id HAVING COUNT(a.Id) > 100 ORDER BY AvgNormalizedScore DESC
2010-08-25 13:57:03
false
9,900
Distribution of scores on my answers
Shows how often a user's answers get a specific score. Related to http://odata.stackexchange.com/stackoverflow/q/1930
DECLARE @totalAnswers DECIMAL SELECT @totalAnswers = COUNT(*) FROM posts WHERE posttypeid = 2 AND owneruserid = ##UserId## AND creationdate > ##postStart:string?2020-01-01## AND DeletionDate is null SELECT score AS AnswerScore, Occurences, CASE WHEN Frequency < 1 THEN '<1%' ELSE Cast(Cast(ROUND(Frequency, 0) AS INT) AS VARCHAR) + '%' END AS Frequency FROM ( SELECT score, COUNT(*) AS Occurences, (COUNT(*) / @totalAnswers) * 100 AS Frequency FROM posts WHERE posttypeid = 2 -- answers AND owneruserid = ##UserId## -- by you AND creationdate > ##postStart:string?2020-01-01## AND DeletionDate is null GROUP BY score ) AS answers ORDER BY answers.Frequency DESC, Score
2020-10-11 20:40:02
false
9,919
Best hour of the day to ask a question
Which UTC hour of the day gets the most accepted answers
SELECT DATEPART(hh, CreationDate), COUNT(*) FROM Posts WHERE PostTypeId = 2 AND ID in ( SELECT AcceptedAnswerID FROM Posts WHERE AcceptedAnswerID IS NOT NULL ) GROUP BY DATEPART(hh, CreationDate) ORDER BY 2 DESC
2010-08-26 09:02:56
false
10,075
How popular is tag X?
List the number of questions tagged with X.
DECLARE @Name AS varchar(100) = '##TagName##' SELECT Tags.TagName AS Name, count(*) AS Total FROM Tags JOIN PostTags ON PostTags.TagId = Tags.Id WHERE Tags.TagName = @Name GROUP BY Tags.TagName ORDER BY Total DESC
2015-12-14 03:00:24
false
10,121
Accounts with my e-mail hash
Find all accounts with an e-mail hash equal to mine.
SELECT COUNT(*) FROM Users WHERE EmailHash IS NOT NULL
2014-07-28 14:30:50
false
10,243
Top 50 Biggest Favorite Lists
Shows the top 50 post favoriters, so that you can browse all those favorites.
SELECT TOP 50 Id AS [User Link], ( SELECT COUNT(*) FROM Votes WHERE VoteTypeId = 5 AND UserId = Users.Id ) AS Favorites FROM Users ORDER BY Favorites DESC
2010-09-04 06:16:57
false
10,386
Users With the Highest Quality Posts (filter reputation)
Enter the minimum reputation that a user must have, and this will show the users who have the highest reputation per post in that group.
DECLARE @MinRep int = ##MinReputation## SELECT Id AS [User Link], Reputation, (SELECT COUNT(*) FROM posts WHERE posts.OwnerUserId = Users.Id ) AS [# Posts], Reputation / (SELECT COUNT(*) FROM posts WHERE posts.OwnerUserId = Users.Id ) AS [Rep Per Post] FROM Users WHERE Reputation > @MinRep ORDER BY [Rep Per Post] DESC
2010-09-05 09:22:33
false
10,392
Your Posting Quality (Reputation per Posts)
Enter your user ID and find out how much rep you earn per post
SELECT TOP 2000 ROW_NUMBER() OVER (ORDER BY Reputation DESC) AS [rank], Id AS [User Link], Id, Reputation, counts.[# Posts], Reputation / counts.[# Posts] AS [Rep Per Post] FROM Users CROSS APPLY ( SELECT COUNT(*) FROM posts WHERE posts.OwnerUserId = Users.Id ) counts([# Posts]) WHERE counts.[# Posts] > 0 ORDER BY [Rep Per Post] DESC
2020-01-29 16:20:52
false
10,437
Users With the Highest Quality Posts (filter num posts)
Enter the minimum number of posts that a user must have, and this will show the users who have the highest reputation per post in that group.
WITH the Highest Quality Posts (filter num posts) -- Enter the minimum number of posts that a user must have, and this will show the -- users who have the highest reputation per post in that group. SELECT Id AS [User Link], Reputation, Reputation * 1.0 / C.Cnt AS [Rep Per Post] FROM Users U INNER JOIN ( SELECT OwnerUserId, Cnt = Count(*) FROM posts GROUP BY OwnerUserID HAVING Count(*) >= ##MinNumberOfPosts## ) C ON U.Id = C.OwnerUserId ORDER BY [Rep Per Post] DESC
2010-09-06 03:31:04
false
10,747
How many votes do I receive per answer?
On average, how many upvotes do I receive for each answer I give?
DECLARE @UserID int = ##UserId##; WITH VotesOnPosts AS ( SELECT v.Id AS VoteId , p.Id AS PostId , p.PostTypeId AS PostTypeId , p.OwnerUserId AS UserId , vt.Name AS VoteTypeName FROM Votes v INNER JOIN Posts p ON v.PostId = p.Id INNER JOIN VoteTypes vt ON v.voteTypeId = vt.Id ) , Answers AS (SELECT OwnerUserId AS UserId, Id AS PostId FROM Posts WHERE PostTypeId = 2) , Counts AS ( SELECT (SELECT COUNT(*) FROM VotesOnPosts WHERE VoteTypeName = 'UpMod' AND UserId = @UserID AND PostTypeId = 2) AS TotalUpVotes, (SELECT COUNT(*) FROM Answers WHERE UserId = @UserID) AS TotalAnswers ) SELECT TotalUpVotes, TotalAnswers, (CAST(TotalUpVotes AS float) / TotalAnswers) AS VotesPerAnswer FROM Counts
2010-09-11 02:59:15
false