Re: count(boolean)
От | Jean-Luc Lachance |
---|---|
Тема | Re: count(boolean) |
Дата | |
Msg-id | 3CE9117F.183B58EE@nsd.ca обсуждение исходный текст |
Ответ на | Re: Casting timestamp ("Joel Burton" <joel@joelburton.com>) |
Список | pgsql-sql |
Dan, Try: SELECT question_id AS id, count( case when value then 1 else 0 end) as count_true, count( case when value then 0 else 1end) as count_false FROM answers_boolean GROUP BY question_id; jll Dan MacNeil wrote: > > I have a table answers_boolean: > > question_id | integer | not null > evaluation_id | integer | not null > value | boolean | > > I'd like output in the form: > > question_id, count_true, count_false > > ....where count_true is the number of questions answered "true" > > SELECT > question_id AS id, value AS val , count(value) AS cnt > FROM > answers_boolean > GROUP BY > question_id,value; > > gives me: > id | val | cnt > ----+-----+----- > 2 | f | 3 > 2 | t | 3 > 3 | f | 2 > 3 | t | 4 > > ...which is sorta what I want. > > I've looked through the docs & archive but haven't found the answer. > > TIA > > ---------------------------(end of broadcast)--------------------------- > TIP 3: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that your > message can get through to the mailing list cleanly
В списке pgsql-sql по дате отправления: