The seasoned Zombie sniper: a query to find unanswered questions with specific tags












5














The query (on SEDE)



This query builds upon the previous and includes the suggestions by rofl as well as the now mentioned activity index.



DECLARE @tag_name nvarchar(35) = '##TagName##';
DECLARE @min_score int = ##MinScore:int?0##;
DECLARE @max_score int = ##MaxScore:int?0##;

-- CTE to find the maximum answer score on a question. Originally suggested by
-- rofl on https://codereview.stackexchange.com/a/189966/21002
WITH BestAnswer AS (
SELECT
ParentId,
Max(Score) as Score,
MAX(LastActivityDate) as LastActivityDate
FROM Posts
WHERE PostTypeId = 2
GROUP BY ParentId
)

SELECT
q.Id AS [Post Link],
q.Tags,
q.LastActivityDate as [Last question activity],
a.LastActivityDate as [Last answer activity],
CAST(a.LastActivityDate - q.LastActivityDate as int) as [Activity Index]
FROM
Posts q
INNER JOIN PostTags pt
ON q.Id = pt.PostId
INNER JOIN Tags t
ON pt.TagId = t.id
AND t.TagName = @tag_name
INNER JOIN BestAnswer a
ON q.Id = a.ParentId
AND a.Score >= @min_score
AND a.Score <= @max_score
WHERE
q.PostTypeId = 1
AND q.ClosedDate IS NULL
AND q.AnswerCount > 0
AND q.AcceptedAnswerId IS NULL
ORDER BY
[Activity Index] DESC,
q.LastActivityDate ASC

-- TagName: Tag name as you would use in your post
-- MinScore: Highest answer has at least votes:
-- MaxScore: Highest answer has at most votes:


This will probably be the last one in the Zombie series.



Motivation



Zombies! The dread of any barbecue. The grilled brains are sticky, their odour is icky, and they never stop talking about crossdead. But that is not the kind of Zombie we suffer from.



We are looking for easy-to revive question Zombies. Questions, that have at least one 0-score answer but count as /unanswered. A revival just needs a single click in those cases: an upvote. We only need to find those Schroedinger questions and cure them.



The first cure accidentally included closed questions, as did the second. This query remedies this fault and only looks for the Zombies that haven't been thrown into jail. It also includes an activity index (see below).



The goal



The previous questions have shown that the requirements on the query were not really communicated well. This time I'll try to list all requirements for the query:




  • it must consist of a subset of /unanswered:


    • it must not contain closed questions

    • it must not contain questions that have an accepted answer

    • it must not contain questions that have an answer with a positive (>0) score, unless the MaxScore is greater than 0



  • it must not contain questions that have answers with a score greater than the MaxScore

  • it must not contain questions that have answers with a score lesser than the MinScore

  • it should only return questions that have been tagged with ##Tagname##

  • it should include the last activity date of the question

  • it should include the latest activity date the question's answers

  • it should include an activity index

  • it should order the results by the activity index descending first and then ascending by date.


The activity index is basically the difference between the last question activity and the latest question's answers' activity, e.g.



$$ text{activity_index} = max_{a text{ answers } q} a_{text{LastActivityDate}} - q_{text{LastActivityDate}}. $$



Since any answer activity automatically updates the question's LastActivityDate it is always non-positive. The lower the index, the more likely that a new answer is necessary and the current 0-score answer is insufficient or misses the point.










share|improve this question

















This question has an open bounty worth +50
reputation from Zeta ending in 7 days.


This question has not received enough attention.
















  • Does it take into account the question score? I ran vba - 0 - 0 and this was the first result, with a positive answer- codereview.stackexchange.com/questions/180309/…
    – Raystafarian
    Mar 24 at 22:57






  • 1




    @Raystafarian the SEDE dataset is cached (see FAQ at the bottom). So the answer was updated. And no, the question's score is not taken into account, as it would still show up on /unanswered.
    – Zeta
    Mar 24 at 23:02












  • Ah, makes sense. didn't realize votes don't change the activity date
    – Raystafarian
    Mar 24 at 23:04
















5














The query (on SEDE)



This query builds upon the previous and includes the suggestions by rofl as well as the now mentioned activity index.



DECLARE @tag_name nvarchar(35) = '##TagName##';
DECLARE @min_score int = ##MinScore:int?0##;
DECLARE @max_score int = ##MaxScore:int?0##;

-- CTE to find the maximum answer score on a question. Originally suggested by
-- rofl on https://codereview.stackexchange.com/a/189966/21002
WITH BestAnswer AS (
SELECT
ParentId,
Max(Score) as Score,
MAX(LastActivityDate) as LastActivityDate
FROM Posts
WHERE PostTypeId = 2
GROUP BY ParentId
)

SELECT
q.Id AS [Post Link],
q.Tags,
q.LastActivityDate as [Last question activity],
a.LastActivityDate as [Last answer activity],
CAST(a.LastActivityDate - q.LastActivityDate as int) as [Activity Index]
FROM
Posts q
INNER JOIN PostTags pt
ON q.Id = pt.PostId
INNER JOIN Tags t
ON pt.TagId = t.id
AND t.TagName = @tag_name
INNER JOIN BestAnswer a
ON q.Id = a.ParentId
AND a.Score >= @min_score
AND a.Score <= @max_score
WHERE
q.PostTypeId = 1
AND q.ClosedDate IS NULL
AND q.AnswerCount > 0
AND q.AcceptedAnswerId IS NULL
ORDER BY
[Activity Index] DESC,
q.LastActivityDate ASC

-- TagName: Tag name as you would use in your post
-- MinScore: Highest answer has at least votes:
-- MaxScore: Highest answer has at most votes:


This will probably be the last one in the Zombie series.



Motivation



Zombies! The dread of any barbecue. The grilled brains are sticky, their odour is icky, and they never stop talking about crossdead. But that is not the kind of Zombie we suffer from.



We are looking for easy-to revive question Zombies. Questions, that have at least one 0-score answer but count as /unanswered. A revival just needs a single click in those cases: an upvote. We only need to find those Schroedinger questions and cure them.



The first cure accidentally included closed questions, as did the second. This query remedies this fault and only looks for the Zombies that haven't been thrown into jail. It also includes an activity index (see below).



The goal



The previous questions have shown that the requirements on the query were not really communicated well. This time I'll try to list all requirements for the query:




  • it must consist of a subset of /unanswered:


    • it must not contain closed questions

    • it must not contain questions that have an accepted answer

    • it must not contain questions that have an answer with a positive (>0) score, unless the MaxScore is greater than 0



  • it must not contain questions that have answers with a score greater than the MaxScore

  • it must not contain questions that have answers with a score lesser than the MinScore

  • it should only return questions that have been tagged with ##Tagname##

  • it should include the last activity date of the question

  • it should include the latest activity date the question's answers

  • it should include an activity index

  • it should order the results by the activity index descending first and then ascending by date.


The activity index is basically the difference between the last question activity and the latest question's answers' activity, e.g.



$$ text{activity_index} = max_{a text{ answers } q} a_{text{LastActivityDate}} - q_{text{LastActivityDate}}. $$



Since any answer activity automatically updates the question's LastActivityDate it is always non-positive. The lower the index, the more likely that a new answer is necessary and the current 0-score answer is insufficient or misses the point.










share|improve this question

















This question has an open bounty worth +50
reputation from Zeta ending in 7 days.


This question has not received enough attention.
















  • Does it take into account the question score? I ran vba - 0 - 0 and this was the first result, with a positive answer- codereview.stackexchange.com/questions/180309/…
    – Raystafarian
    Mar 24 at 22:57






  • 1




    @Raystafarian the SEDE dataset is cached (see FAQ at the bottom). So the answer was updated. And no, the question's score is not taken into account, as it would still show up on /unanswered.
    – Zeta
    Mar 24 at 23:02












  • Ah, makes sense. didn't realize votes don't change the activity date
    – Raystafarian
    Mar 24 at 23:04














5












5








5


2





The query (on SEDE)



This query builds upon the previous and includes the suggestions by rofl as well as the now mentioned activity index.



DECLARE @tag_name nvarchar(35) = '##TagName##';
DECLARE @min_score int = ##MinScore:int?0##;
DECLARE @max_score int = ##MaxScore:int?0##;

-- CTE to find the maximum answer score on a question. Originally suggested by
-- rofl on https://codereview.stackexchange.com/a/189966/21002
WITH BestAnswer AS (
SELECT
ParentId,
Max(Score) as Score,
MAX(LastActivityDate) as LastActivityDate
FROM Posts
WHERE PostTypeId = 2
GROUP BY ParentId
)

SELECT
q.Id AS [Post Link],
q.Tags,
q.LastActivityDate as [Last question activity],
a.LastActivityDate as [Last answer activity],
CAST(a.LastActivityDate - q.LastActivityDate as int) as [Activity Index]
FROM
Posts q
INNER JOIN PostTags pt
ON q.Id = pt.PostId
INNER JOIN Tags t
ON pt.TagId = t.id
AND t.TagName = @tag_name
INNER JOIN BestAnswer a
ON q.Id = a.ParentId
AND a.Score >= @min_score
AND a.Score <= @max_score
WHERE
q.PostTypeId = 1
AND q.ClosedDate IS NULL
AND q.AnswerCount > 0
AND q.AcceptedAnswerId IS NULL
ORDER BY
[Activity Index] DESC,
q.LastActivityDate ASC

-- TagName: Tag name as you would use in your post
-- MinScore: Highest answer has at least votes:
-- MaxScore: Highest answer has at most votes:


This will probably be the last one in the Zombie series.



Motivation



Zombies! The dread of any barbecue. The grilled brains are sticky, their odour is icky, and they never stop talking about crossdead. But that is not the kind of Zombie we suffer from.



We are looking for easy-to revive question Zombies. Questions, that have at least one 0-score answer but count as /unanswered. A revival just needs a single click in those cases: an upvote. We only need to find those Schroedinger questions and cure them.



The first cure accidentally included closed questions, as did the second. This query remedies this fault and only looks for the Zombies that haven't been thrown into jail. It also includes an activity index (see below).



The goal



The previous questions have shown that the requirements on the query were not really communicated well. This time I'll try to list all requirements for the query:




  • it must consist of a subset of /unanswered:


    • it must not contain closed questions

    • it must not contain questions that have an accepted answer

    • it must not contain questions that have an answer with a positive (>0) score, unless the MaxScore is greater than 0



  • it must not contain questions that have answers with a score greater than the MaxScore

  • it must not contain questions that have answers with a score lesser than the MinScore

  • it should only return questions that have been tagged with ##Tagname##

  • it should include the last activity date of the question

  • it should include the latest activity date the question's answers

  • it should include an activity index

  • it should order the results by the activity index descending first and then ascending by date.


The activity index is basically the difference between the last question activity and the latest question's answers' activity, e.g.



$$ text{activity_index} = max_{a text{ answers } q} a_{text{LastActivityDate}} - q_{text{LastActivityDate}}. $$



Since any answer activity automatically updates the question's LastActivityDate it is always non-positive. The lower the index, the more likely that a new answer is necessary and the current 0-score answer is insufficient or misses the point.










share|improve this question















The query (on SEDE)



This query builds upon the previous and includes the suggestions by rofl as well as the now mentioned activity index.



DECLARE @tag_name nvarchar(35) = '##TagName##';
DECLARE @min_score int = ##MinScore:int?0##;
DECLARE @max_score int = ##MaxScore:int?0##;

-- CTE to find the maximum answer score on a question. Originally suggested by
-- rofl on https://codereview.stackexchange.com/a/189966/21002
WITH BestAnswer AS (
SELECT
ParentId,
Max(Score) as Score,
MAX(LastActivityDate) as LastActivityDate
FROM Posts
WHERE PostTypeId = 2
GROUP BY ParentId
)

SELECT
q.Id AS [Post Link],
q.Tags,
q.LastActivityDate as [Last question activity],
a.LastActivityDate as [Last answer activity],
CAST(a.LastActivityDate - q.LastActivityDate as int) as [Activity Index]
FROM
Posts q
INNER JOIN PostTags pt
ON q.Id = pt.PostId
INNER JOIN Tags t
ON pt.TagId = t.id
AND t.TagName = @tag_name
INNER JOIN BestAnswer a
ON q.Id = a.ParentId
AND a.Score >= @min_score
AND a.Score <= @max_score
WHERE
q.PostTypeId = 1
AND q.ClosedDate IS NULL
AND q.AnswerCount > 0
AND q.AcceptedAnswerId IS NULL
ORDER BY
[Activity Index] DESC,
q.LastActivityDate ASC

-- TagName: Tag name as you would use in your post
-- MinScore: Highest answer has at least votes:
-- MaxScore: Highest answer has at most votes:


This will probably be the last one in the Zombie series.



Motivation



Zombies! The dread of any barbecue. The grilled brains are sticky, their odour is icky, and they never stop talking about crossdead. But that is not the kind of Zombie we suffer from.



We are looking for easy-to revive question Zombies. Questions, that have at least one 0-score answer but count as /unanswered. A revival just needs a single click in those cases: an upvote. We only need to find those Schroedinger questions and cure them.



The first cure accidentally included closed questions, as did the second. This query remedies this fault and only looks for the Zombies that haven't been thrown into jail. It also includes an activity index (see below).



The goal



The previous questions have shown that the requirements on the query were not really communicated well. This time I'll try to list all requirements for the query:




  • it must consist of a subset of /unanswered:


    • it must not contain closed questions

    • it must not contain questions that have an accepted answer

    • it must not contain questions that have an answer with a positive (>0) score, unless the MaxScore is greater than 0



  • it must not contain questions that have answers with a score greater than the MaxScore

  • it must not contain questions that have answers with a score lesser than the MinScore

  • it should only return questions that have been tagged with ##Tagname##

  • it should include the last activity date of the question

  • it should include the latest activity date the question's answers

  • it should include an activity index

  • it should order the results by the activity index descending first and then ascending by date.


The activity index is basically the difference between the last question activity and the latest question's answers' activity, e.g.



$$ text{activity_index} = max_{a text{ answers } q} a_{text{LastActivityDate}} - q_{text{LastActivityDate}}. $$



Since any answer activity automatically updates the question's LastActivityDate it is always non-positive. The lower the index, the more likely that a new answer is necessary and the current 0-score answer is insufficient or misses the point.







beginner sql sql-server t-sql stackexchange






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 0:30









Jamal

30.2k11116226




30.2k11116226










asked Mar 24 at 8:23









Zeta

14.8k23371




14.8k23371






This question has an open bounty worth +50
reputation from Zeta ending in 7 days.


This question has not received enough attention.








This question has an open bounty worth +50
reputation from Zeta ending in 7 days.


This question has not received enough attention.














  • Does it take into account the question score? I ran vba - 0 - 0 and this was the first result, with a positive answer- codereview.stackexchange.com/questions/180309/…
    – Raystafarian
    Mar 24 at 22:57






  • 1




    @Raystafarian the SEDE dataset is cached (see FAQ at the bottom). So the answer was updated. And no, the question's score is not taken into account, as it would still show up on /unanswered.
    – Zeta
    Mar 24 at 23:02












  • Ah, makes sense. didn't realize votes don't change the activity date
    – Raystafarian
    Mar 24 at 23:04


















  • Does it take into account the question score? I ran vba - 0 - 0 and this was the first result, with a positive answer- codereview.stackexchange.com/questions/180309/…
    – Raystafarian
    Mar 24 at 22:57






  • 1




    @Raystafarian the SEDE dataset is cached (see FAQ at the bottom). So the answer was updated. And no, the question's score is not taken into account, as it would still show up on /unanswered.
    – Zeta
    Mar 24 at 23:02












  • Ah, makes sense. didn't realize votes don't change the activity date
    – Raystafarian
    Mar 24 at 23:04
















Does it take into account the question score? I ran vba - 0 - 0 and this was the first result, with a positive answer- codereview.stackexchange.com/questions/180309/…
– Raystafarian
Mar 24 at 22:57




Does it take into account the question score? I ran vba - 0 - 0 and this was the first result, with a positive answer- codereview.stackexchange.com/questions/180309/…
– Raystafarian
Mar 24 at 22:57




1




1




@Raystafarian the SEDE dataset is cached (see FAQ at the bottom). So the answer was updated. And no, the question's score is not taken into account, as it would still show up on /unanswered.
– Zeta
Mar 24 at 23:02






@Raystafarian the SEDE dataset is cached (see FAQ at the bottom). So the answer was updated. And no, the question's score is not taken into account, as it would still show up on /unanswered.
– Zeta
Mar 24 at 23:02














Ah, makes sense. didn't realize votes don't change the activity date
– Raystafarian
Mar 24 at 23:04




Ah, makes sense. didn't realize votes don't change the activity date
– Raystafarian
Mar 24 at 23:04















active

oldest

votes











Your Answer





StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");

StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f190356%2fthe-seasoned-zombie-sniper-a-query-to-find-unanswered-questions-with-specific-t%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Code Review Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f190356%2fthe-seasoned-zombie-sniper-a-query-to-find-unanswered-questions-with-specific-t%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

Refactoring coordinates for Minecraft Pi buildings written in Python