Calculate the difference between results of two count(*) queries based on 2 tables in PostgreSQL
Try this way:
select
(
SELECT
"count"(*) as val1
from
tab1
) - (
SELECT
"count"(*) as val2
from
tab2
) as total_count
select t1.cnt - t2.cnt
from (select count(*) as cnt from tab1) as t1
cross join (select count(*) as cnt from tab2) as t2
for same table you can do this.
select (count(abc)-count(DISTINCT xyz)) from tab;