Q&A about the site for operations research and analytics professionals, educators, and students
-- Define a table to store sampled question ids DECLARE @question_ids table(Id int); INSERT INTO @question_ids SELECT TOP 100 Id FROM Posts WHERE (Title IS NOT NULL AND Body IS NOT NULL AND Tags IS NOT NULL) and Score > 10 ORDER BY NEWID(); -- get a random set of questions into the table defined above SELECT TOP 100 Posts.Id, Posts.Body, Posts.Title, Posts.Tags, Posts.CreationDate, Posts.Score FROM @question_ids as QIDs INNER JOIN Posts ON QIDs.Id = Posts.Id; -- Download top 50K tags SELECT TOP 50000 Id, TagName, Count FROM Tags WHERE TagName IS NOT NULL ORDER BY Count DESC; -- Counting the number of rows: SELECT COUNT(Id) AS TotalRowCount FROM Posts; -- Counting the number of complete Posts: SELECT COUNT(*) AS CompletePostsCount FROM Posts WHERE Title IS NOT NULL AND Tags IS NOT NULL AND Body IS NOT NULL; -- Select random posts from a slice of 1:10 of total data selecting posts with score higher than 10 and non-empty tags, title, and comment: DECLARE @Counter INT; SET @Counter = (SELECT COUNT(Id) FROM Posts); SELECT TOP 50000 Id, Body, Title, Tags, Score, CreationDate FROM Posts WHERE 2*@Counter/10 < Id AND Id < 3*@Counter/10 AND Title IS NOT NULL AND Body IS NOT NULL AND Tags IS NOT NULL AND Score > 10 ORDER BY NEWID(); -- Random value sampling with replacement: DECLARE @Counter2 INT; SET @Counter2 = 1; DECLARE @Randint INT; WHILE (@Counter2 <= 10) BEGIN SET @Randint = CAST(RAND() * (10 - 5) + 5 AS INT); PRINT 'The counter value is ' + CONVERT(VARCHAR, @Counter2); PRINT 'The random value is ' + CONVERT(VARCHAR, @Randint); SET @Counter2 = @Counter2 + 1; END; -- Select all tag synonyms: SELECT * FROM TagSynonyms;