我有下表:
(table from a previous query)
count(method) top_url Tor
4 http://check.torproject.org Tor
4 http://check.torproject.org NoTor
5 http://thebay.ca Tor
119 http://thebay.ca NoTor
10 http://test.com Tor
5 http://test.com NoTor
我想从同一个top_url中获取每一行之间的差异。如果可能的话,我想获得绝对值(如果有的话,删除减号)。
上一表的输出为:
Diff top_url
0 http://check.torproject.org
114 http://thebay.ca
5 http://test.com
答案 0 :(得分:1)
一种选择是使用带有条件聚合的abs()
:
select top_url,
abs(max(case when tor = 'Tor' then methodcount else 0 end) -
max(case when tor = 'NoTor' then methodcount else 0 end))
from yourresults
group by top_url;