Zählen verschiedener Zeilenkombinationen einer Zabelle mit einer Abfrage

Hallo,

ich habe eine Tabelle in diesem Stil:

typ1|typ2|typ3
----------
a   |a   |a
a   |a   |b
a   |a   |c
a   |b   |d
a   |b   |e
a   |c   |f

mit

select destinct typ1, count(typ2), count(typ3) from tabelle group by typ1;

wollte ich alle verschiedenen Kombinationen typ1:typ2 und in einer weiteren Spalte typ1:typ3 - ich hatte also auf folgendes Ergebnis gehofft:

typ1|typ2|typ3
a   |3   |6

stattdessen bekomme ich:

typ1|typ2|typ3
a   |6   |6

vermutlich, da sich die kompletten Zeilen unterscheiden. Geht dass denn in einer einzelnen Abfrage und wenn dann wie?
Vielen Dank.

Hi,

versuch doch mal:

select destinct typ1, count(distinct typ2), count(distinct typ3) from tabelle group by typ1;

Ist die este Spalte konstant?

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.

Andreas

Yeah, und nun noch s/destinct/distinct/, aber ja, warum einfach, wenn es auch kompliziert geht …


Andreas

Funktioniert wunderbar - vielen Dank!