Re: SQL problem with aggregate functions.
От | Christoph Haller |
---|---|
Тема | Re: SQL problem with aggregate functions. |
Дата | |
Msg-id | 200207110837.KAA07881@rodos обсуждение исходный текст |
Ответ на | SQL problem with aggregate functions. (David BOURIAUD <david.bouriaud@ac-rouen.fr>) |
Ответы |
Re: SQL problem with aggregate functions.
|
Список | pgsql-sql |
> > I've got a table in which there is a field that can have one amongst 3 > possible values : D, R, X. Is it possible to get in one query the count of > this different values.Please, note that I don't want to have a querry like > this : > "select count (*) from tab group by f1;", cause i want to get all the possible > count values in one row (these data are already grouped on another field). > To give a more accurate example, here is what I want to retrieve : > > Field group | count of D | count of R | count of X. > > Any clues ? > -- What about something like SELECT SUM(f1_d) AS count_d, SUM(f1_r) AS count_r, SUM(f1_x) AS count_x FROM (SELECT CASE WHEN f1 = 'D' THEN 1 ELSE 0 END AS f1_d, CASE WHEN f1 = 'R' THEN 1 ELSE 0 END AS f1_r, CASEWHEN f1 = 'X' THEN 1 ELSE 0 END AS f1_xFROM tab ) AS foo ; Regards, Christoph
В списке pgsql-sql по дате отправления: