Work in progress

0

Please login or register to vote for this query.

(click on this box to dismiss)

Craft CMS Meta

Q&A about the site for administrators, end users, developers and designers for Craft CMS

DECLARE @Users     TABLE
    (
    UserId         INT PRIMARY KEY,
    QuestionCount  INT
    )

INSERT INTO
    @Users
    
SELECT
    Users.Id                         AS UserId,
    COUNT( DISTINCT Question.Id )    AS QuestionCount
    
FROM
    Users
    
    INNER JOIN
    Posts                            AS Question
    ON  Users.Id                     = Question.OwnerUserId
    
WHERE
        Question.PostTypeId          = 1 --questions
    AND Users.CreationDate           > '1/1/2010'
    AND Question.AnswerCount         > 0
    
GROUP BY
    Users.Id
    
HAVING
    COUNT( DISTINCT Question.Id )    > 5 



DECLARE @Accepted     TABLE
    (
    UserId            INT PRIMARY KEY
    )

INSERT INTO
    @Accepted
   
SELECT
    Users.UserId                     AS UserId
    
FROM
    @Users                           AS Users
    
    INNER JOIN
    Posts                            AS Accepted
    ON  Users.UserId                 = Accepted.OwnerUserId
    
WHERE
        Accepted.PostTypeId          = 1 --questions
    AND Accepted.AcceptedAnswerId    IS NOT NULL
AND Users.UserId = 984621    
GROUP BY
    Users.UserId


/*
SELECT
    Users.UserId           AS [User Link],
    Users.QuestionCount    AS [Question Count]
    
FROM
    @Users                 AS Users
    
    LEFT JOIN
    @Accepted              AS Accepted
    ON Users.UserId        = Accepted.UserId

ORDER BY
    Users.QuestionCount    DESC
  */  
    
SELECT * FROM @Users WHERE UserId = 984621
--SELECT * FROM @Unaccepted WHERE UserId = 984621
SELECT Posts.Id, Posts.AcceptedAnswerId, Posts.AnswerCount FROM Posts 
WHERE OwnerUserId = 984621 AND Posts.AnswerCount > 0 AND PostTypeId = 1

Enter Parameters

Options:
Switch to main site
loading Hold tight while we fetch your results