Last active
January 23, 2019 12:41
-
-
Save poojithansl/0f0cfb2b008a1be39dba7f52cbc39ebc to your computer and use it in GitHub Desktop.
Sql - StackExchange
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Get Question Id, title and Body | |
select Q.Id, Q.Title, G.Body | |
from | |
Posts as G, | |
(select * from Posts | |
where ParentId is null | |
and Title like 'How to%' or Title like 'how to%') | |
as Q | |
where G.ParentId = Q.Id | |
-- Questions with more than 5 answers | |
select Q.Id as QId, Q.Title as QTitle, Q.body as QBody, G.Id as GId, G.Body as GBody, Q.Score as QScore, G.Score as GScore, | |
Q.ViewCount as QViewCount, G.ViewCount as GViewCount, Q.Tags as QTags, G.Title as GTitle | |
from | |
Posts as G, | |
(select * from Posts | |
where ParentId is null | |
and AnswerCount>=5) | |
as Q | |
where G.ParentId = Q.Id | |
-- Not required to know | |
Select 'Data.StackExchange' As [DatabaseName], Q.Id, G.Body From [Data.StackExchange].dbo.[Posts] as G, | |
( select * From [Data.StackExchange].Posts where ParentId is null | |
) as Q | |
where G.ParentId = Q.Id UNION ALL | |
Select 'master' As [DatabaseName], Q.Id, G.Body From [master]..Posts as G, | |
( select * From [master]..Posts where ParentId is null | |
) as Q | |
where G.ParentId = Q.Id | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment