プログラマーと熱狂的なプログラマーのためのサイトに関する質問と回答
declare @user_id int = ##UserId:int## ; WITH DownvotedPosts AS ( SELECT p.Id as [Post Link], p.Score, sum(case when p.Id = v.PostId then 1 else 0 end) as [Downvotes] FROM Posts p inner join Votes v on p.Id = v.PostId WHERE p.OwnerUserId = @user_id -- and v.VoteTypeId=3 and p.Title like '%java%' GROUP BY p.Id, p.Score ) SELECT * FROM DownvotedPosts -- ORDER BY Downvotes DESC, Score DESC