patternsqlMinor
Finding bad Narutos
Viewed 0 times
badnarutosfinding
Problem
While looking for Naruto posts
(= overlooked accepted answers well worthy of upvotes),
I noticed some odd false positives,
selfie answers,
where the user who asked the question accepted his own answer under suspicious circumstances.
I'd call suspicious circumstance the case when other answers exist with positive votes,
while the selfie has
Also keep in mind that the data of SEDE is not up to date,
so when you find already flagged or upvoted selfie accepts,
it doesn't mean the query is broken.
(= overlooked accepted answers well worthy of upvotes),
I noticed some odd false positives,
selfie answers,
where the user who asked the question accepted his own answer under suspicious circumstances.
I'd call suspicious circumstance the case when other answers exist with positive votes,
while the selfie has
- Good selfies may actually deserve upvotes
Also keep in mind that the data of SEDE is not up to date,
so when you find already flagged or upvoted selfie accepts,
it doesn't mean the query is broken.
Solution
It looks good to me. Just a minor funky format thing going on here in the very first CTE.
You might want to consider some newlines and extra indentation for that last
WITH AcceptedAnswers AS (
SELECT Id, ParentId, Score, OwnerUserId, CreationDate
FROM Posts
WHERE PostTypeId = 2
AND (@userId < 0 OR OwnerUserId = @userId)
AND (@username = '' OR OwnerUserId IN (
SELECT Id
FROM Users
WHERE DisplayName = @username))You might want to consider some newlines and extra indentation for that last
AND.WITH AcceptedAnswers AS (
SELECT Id, ParentId, Score, OwnerUserId, CreationDate
FROM Posts
WHERE PostTypeId = 2
AND (@userId < 0 OR OwnerUserId = @userId)
AND (@username = ''
OR OwnerUserId IN (
SELECT Id
FROM Users
WHERE DisplayName = @username
)
)Code Snippets
WITH AcceptedAnswers AS (
SELECT Id, ParentId, Score, OwnerUserId, CreationDate
FROM Posts
WHERE PostTypeId = 2
AND (@userId < 0 OR OwnerUserId = @userId)
AND (@username = '' OR OwnerUserId IN (
SELECT Id
FROM Users
WHERE DisplayName = @username))WITH AcceptedAnswers AS (
SELECT Id, ParentId, Score, OwnerUserId, CreationDate
FROM Posts
WHERE PostTypeId = 2
AND (@userId < 0 OR OwnerUserId = @userId)
AND (@username = ''
OR OwnerUserId IN (
SELECT Id
FROM Users
WHERE DisplayName = @username
)
)Context
StackExchange Code Review Q#79174, answer score: 2
Revisions (0)
No revisions yet.