SQL-server without tsql

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

DECLARE @UserId int = ##UserId##

;with cte as (
    select
        p.Id,
        max(case when t.TagName = 'sql' then 1 else 0 end) as [sql],
        max(case when t.TagName = 'sql-server' then 1 else 0 end) as [sql-server],
        max(case when t.TagName = 'postgresql' then 1 else 0 end) as [postgresql],
        max(case when t.TagName = 'mysql' then 1 else 0 end) as [mysql],
        a.Score
    from Posts as p
        inner join PostTags as pt on pt.PostId = p.Id
        inner join Tags as t on t.Id = pt.TagId
        inner join Posts as a on a.ParentId = p.Id
    where
        a.OwnerUserId = @UserId
    group by
        p.Id,
        a.Score
)
select *
from cte
where
    sql = 1 and [sql-server] = 0 and postgresql = 0 and mysql = 0
order by Score desc

Enter Parameters

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