1
with Tagvote as (
SELECT --TOP 20 
p.OwnerUserId,
t.TagName,
COUNT(*) over (partition by p.OwnerUserId Order by t.TagName)AS UpVotes 
FROM Tags t
INNER JOIN PostTags pt ON pt.TagId = t.Id
INNER JOIN Posts p ON p.ParentId = pt.PostId
INNER JOIN Votes v ON v.PostId = p.Id 
WHERE 
 v.VoteTypeId = 2
 and OwnerUserId in 
 (select distinct Id from Users 
 where ID=114899) 
GROUP BY p.OwnerUserId, t.TagName 
),

list as (
select distinct Posts.OwnerUserId as userid, b.TagName from Posts,
       (Select distinct t.TagName from Tags t) as b
     where Posts.OwnerUserId in 
       (select distinct id from Users 
     where ID=114899)      
select distinct 
            l.userid,
            l.TagName,
            Tagvote.UpVotes as [votetag]
            from list l
            left outer join Tagvote on Tagvote.TagName=l.TagName 
            and l.userid=Tagvote.OwnerUserId
            ORDER BY v.userid asc, v.UpVote DESC
            ;
4

0 回答 0