sqldataexplorer

Getting a list of questions from Code Golf where answers could be eligible for bounty from Jo King using SEDE


So on Code Golf.SE, there is a meta post that allows users to post unofficial bounties where a certain feat must be accomplished before a bounty can be awarded.

@JoKing has a deadlineless bounty where 200 reputation will be awarded if these requirements are met:

I, of course, wanted to know what questions would qualify as of right now, and went straight to SEDE to see if I could cook up a program that would allow me to see which questions would be eligible. Right now, this is what I have:

SELECT p.Id AS [Post Link], u.DisplayName, p.Score, p.ViewCount, p.Tags
FROM Posts p
JOIN Users u ON p.OwnerUserId = u.Id
INNER JOIN PostTags pt ON p.Id = pt.PostId
INNER JOIN Tags t ON t.Id = pt.TagId
WHERE p.PostTypeId = 1
AND NOT (p.Tags LIKE '%tips%' OR p.Tags LIKE '%king-of-the-hill%' OR p.Tags LIKE '%cops-and-robbers%')
AND p.Score >= 15
AND p.AcceptedAnswerId IS NULL
ORDER BY p.Score DESC

however I am running into the problem now that yet again, it is returning not only all of the questions, but all of the answers that are posted on questions that don't have the 3 tags I have managed to finally nullify.

For anyone wondering,

AND NOT (t.TagName = ##tagName:string?tips## OR t.TagName = ##tagName:string?king-of-the-hill## OR t.TagName = ##tagName:string?cops-and-robbers##)

does not work, as it also returns questions/answers with those tags.

So my question is: Why is it returning both questions and answers, and how do I make it so it only returns the questions?


Solution

  • Never mind, I figured it out.

    Turns out that the two INNER JOINs aren't even needed.

    I was focusing so much on the code that nullified the tags that it wasn't until @NickW mentioned that there was a 1:M relationship between at least two of the tables I was joining (and around 15 minutes after posting my reply to that comment) that I actually decided to see what would happen if I removed the INNER JOINs.

    The final code:

    SELECT p.Id AS [Post Link], u.DisplayName, p.Score, p.Viewcount, p.Tags
    FROM Posts p
    JOIN Users u ON p.OwnerUserId = u.Id
    WHERE p.PostTypeId = 1
    AND NOT (p.Tags LIKE '%tips%'
    OR p.Tags LIKE '%king-of-the-hill%'
    OR p.Tags LIKE '%cops-and-robbers%')
    AND p.Score >= 15
    AND p.AcceptedAnswerId IS NULL
    ORDER BY p.Score DESC
    

    Query

    I am aware that @JoKing might have more specific restrictions that greatly lower the amount of eligible questions, however, the way it is put, it seems that there are a total of 3644 questions that are eligible for bountied answers.