test=*# select * from foo;
t1 | t2 | t3
----+----+----
a | a | a
a | a | b
a | a | c
a | b | d
a | b | e
a | c | f
(6 rows)
Time: 0,231 ms
test=*# with b1 as (select distinct t1 from foo), b2 as (select count (*) from (select distinct t1, t2 from foo )foo), b3 as(select count (*) from (select distinct t1, t3 from foo)foo) select b1.*, b2.*, b3.* from b1, b2, b3;
t1 | count | count
----+-------+-------
a | 3 | 6
(1 row)
Falls nein, müßte man das noch etwas umbauen, ich denke mal, man bräuchte dann 2 Ebenen mit WITH um die ersten Spalte als WHERE-Condition verwenden zu können. Aber vielleicht reicht Dir das ja als Anregung.