gpt4 book ai didi

sql - 获取两行的值之差,另一行具有相同的值

转载 作者:行者123 更新时间:2023-12-03 19:41:04 27 4
gpt4 key购买 nike

我有下表:

(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

最佳答案

一种选择是将use 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;



SQL Fiddle Demo

关于sql - 获取两行的值之差,另一行具有相同的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28901257/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com