-1
实施例的数据:父子超过ID查询
id parent child total isParent isParentCHildthing
1 J NA 5 1 1
1 B NA -5 0 1
1 J NA -10 1 1
1 B NA 10 0 1
2 X NA -1 1 1
2 Y NA 1 0 1
3 Z NA 6 0 1
3 W NA 7 0 1
3 P NA -6 1 1
3 R NA -7 1 1
3 TT YY 500 0 0
希望的输出:
id parent child total
1 J B 5
1 J B -10
2 X Y -1
3 P Z -6
3 R W -7
在伪/英语,一种用于在给定id的每个“配对”,我希望父和父母的总值和“子”是与父进程会被isparent = 0 and total = total*-1 where isParent = 1
确定的任何建议,欢迎
建议你看网上书籍中的Recusive CTE。 – HLGEM