我有一张这样的桌子
userEmail | views
A 8
B 3
C 4
A 2
B 5
我想获得特定用户的排名,比如 B ..
我正在做的是:
SET @rank=0;
select @rank:=@rank+1 AS rank , userEmail,sum(views) as views from mtable where userEmail != 'null' Group By userEmail Order By views DESC
这将输出如下内容:
rank | userEmail | views
1 A 10
2 B 8
3 C 4
我可以获得所有用户的排名,但如果我只想查看一个用户的排名怎么办?
如果我where userEmail = 'B'
输入上述查询
我会得到这个:
rank | userEmail | views
1 B 8
但它应该是这样的:
rank | userEmail | views
2 B 8