我很难让我的查询做我想做的事......
如果我为一个 UserId: 2140173 运行它,它似乎工作正常
Select UserId,
(Select Count(VoteTypeId) From SuggestedEditVotes where UserId = 2140173) as 'Total',
(Select Count(VoteTypeId) From SuggestedEditVotes where UserId = 2140173 and VoteTypeId = 2) As 'Accepted',
(Select Count(VoteTypeId) From SuggestedEditVotes where UserId = 2140173 and VoteTypeId = 3) As 'Rejected'
from SuggestedEditVotes
inner join Users on SuggestedEditVotes.UserId = Users.Id
where Users.Reputation > 2000 and UserId = 2140173
group by UserId
having Count(VoteTypeId) > 0
它返回
UserId Total Accepted Rejected
2140173 2230 1145 1085
但是当我试图稍微修改它并为所有拥有超过 2000 名声望的用户运行它时,它并没有给我正确的结果:/
我被 sub Select 语句卡住了,因为我不确定在他们的where
子句中放什么..
这是我尝试过的,但它返回总数,我希望它是每个用户 ID 的计数
Select UserId,
(Select Count(VoteTypeId) From SuggestedEditVotes) as 'Total',
(Select Count(VoteTypeId) From SuggestedEditVotes where VoteTypeId = 2) As 'Accepted',
(Select Count(VoteTypeId) From SuggestedEditVotes where VoteTypeId = 3) As 'Rejected'
from SuggestedEditVotes
inner join Users on SuggestedEditVotes.UserId = Users.Id
where Users.Reputation > 2000
group by UserId
having Count(VoteTypeId) > 0
任何人都可以帮忙吗?