i am looking for elegant way to write PostgreSQL version of this query:
SELECT count(distinct a,b) / count(distinct c,d)
FROM t1
GROUP BY e;
It can be done via CONCAT function, but it this case i get huge performance drop.
Each count distinct can be written in this way:
SELECT count(*), e FROM
(SELECT a, b, e FROM t1 GROUP BY a, b, e) as tmp
GROUP BY e;
AND
SELECT count(*), e FROM
(SELECT c, d, e FROM t1 GROUP BY c, d, e) as tmp
GROUP BY e;
But i can't find how to combine them into one query to get final result
Here is create table to test syntax:
CREATE TABLE t1 (
a int,
b int,
c int,
d int,
e int
);