计算两个节点之间的边网方向
Calculate the edge net direction between two nodes either
我需要一些帮助。我希望能够计算 SQL 内边的净方向。数据如下所示:
Select *
from data
Source destination weight
A B 12
C B 5
D A 7
B A 6
F G 20
B C 2
G F 7
我希望最终结果如下所示:
Source destination weight
A B 6
C B 3
D A 7
F G 13
SQL有没有简单的写法?
我正在使用 SQL 服务器。
您可以使用conditional aggregation
和group by
最小,最大如下:
select IIF(source < destination, source, destination) as src,
IIF(source > destination, source, destination) as dest
sum(case when source < destination then weight else -weight end) as weight
from your_Table
group by IIF(source < destination, source, destination),
IIF(source > destination, source, destination)
我需要一些帮助。我希望能够计算 SQL 内边的净方向。数据如下所示:
Select *
from data
Source destination weight
A B 12
C B 5
D A 7
B A 6
F G 20
B C 2
G F 7
我希望最终结果如下所示:
Source destination weight
A B 6
C B 3
D A 7
F G 13
SQL有没有简单的写法?
我正在使用 SQL 服务器。
您可以使用conditional aggregation
和group by
最小,最大如下:
select IIF(source < destination, source, destination) as src,
IIF(source > destination, source, destination) as dest
sum(case when source < destination then weight else -weight end) as weight
from your_Table
group by IIF(source < destination, source, destination),
IIF(source > destination, source, destination)