mam tabulku:
id xxx
1 a
2 b
3 c
4 a
5 b
6 a
7 b
insert into aa (id, xxx) values(1,"a");
insert into aa (id, xxx) values(2,"b");
insert into aa (id, xxx) values(3,"c");
insert into aa (id, xxx) values(4,"a");
insert into aa (id, xxx) values(5,"b");
insert into aa (id, xxx) values(6,"a");
insert into aa (id, xxx) values(7,"b");
a potrebuju jednim sql dotazem ziskat vysledek:
pocet xxx
3 a
3 b
1 c
kde 'pocet' je pocet vyskytu vsech moznych hodnot ktere se vyskytuji v 'xxx' - v tomto pripade 'a', 'b', resp. 'c'
teoreticky by stacilo nejak zacyklit toto:
select count(*) from aa where xxx=(select distinct xxx from aa);
ale, (coz je logicky), zahlasi postgres:
ERROR: more than one row returned by a subquery used as an expression