加法&从多个TABLES POSTGRES中减去多列

时间:2018-01-04 12:38:20

标签: postgresql

  • 表1(和(col_claim)= 100)
  • 表2(总和(col_claim)= 50)

  • 表3(总和(col_release)= 75)

  • 表4(总和(col_release_two)= 25)
select total_claim-total_release;

结果=(100 + 50) - (75 + 25)= 50

1 个答案:

答案 0 :(得分:1)

只需内联子查询并执行算术:

SELECT
    (SELECT SUM(col_claim) FROM table1) +
    (SELECT SUM(col_claim) FROM table2) -
    (SELECT SUM(col_release) FROM table3) -
    (SELECT SUM(col_release_two) FROM table4) AS result;