Q&A for software developers, mathematicians and others interested in cryptography
DECLARE @Keywords nvarchar(100) = '%##Keywords##%' -- Build the filter result set, with an unanswered 'skew' value CREATE TABLE #unanswered (Id int primary key, UnansweredSkew int) INSERT #unanswered SELECT q.Id as Id, CASE WHEN q.AcceptedAnswerId is null THEN -10 WHEN q.AcceptedAnswerId is not null THEN 0 END AS [Total] FROM Posts q WHERE (q.Tags LIKE '%adal%' OR q.Tags LIKE '%adal%') AND LOWER(q.Body) LIKE @Keywords -- Build the weighting result set SELECT TOP 100 p.Id AS [Post Link], p.ViewCount, p.AnswerCount, CASE WHEN p.AcceptedAnswerId is null THEN 'false' ELSE 'true' END AS Answered, ((p.ViewCount * 0.01) + p.AnswerCount + u.UnansweredSkew) AS Weight, CONVERT(VARCHAR(10), p.CreationDate, 1) as Created, CAST((GETDATE() - p.CreationDate) AS INT) as Age, p.Body -- Join the 2 result sets FROM Posts p JOIN #unanswered u ON u.Id = p.Id ORDER BY Answered ASC, Weight DESC