Calculate the difference between results of two count(*) queries based on 2 tables in PostgreSQL

后端 未结 5 1349
孤城傲影
孤城傲影 2020-12-16 10:29

I want to calculate the difference between the results of 2 count(*)-type SELECT queries executed on 2 separate tables of my PostgreSQL database.

This w

5条回答
  •  再見小時候
    2020-12-16 10:57

    Try this way:

    select 
      (
        SELECT 
          "count"(*) as val1 
        from 
          tab1
      ) - (
        SELECT 
          "count"(*) as val2 
        from 
          tab2
      ) as total_count
    

提交回复
热议问题