pg.ddx.io pgsql-sql@postgresql.org mailing list archivehelp / color / mirror / Atom feed
One query for two information... 2+ messages / 2 participants [nested] [flat]
* One query for two information... @ 2000-04-18 14:26 Ed <dziablo@lords.com> 0 siblings, 1 reply; 2+ messages in thread From: Ed @ 2000-04-18 14:26 UTC (permalink / raw) To: pgsql-sql Hi, I have a table containing only a bool filed. I would like to know how many records there is an on many ar true. Is there something I could do to get both answer in only one query... like : select count(*), sum(bool_col) from tablename but there is no sum(bool) function that would add 1 if it's true and 0 if it's false... ;( Any idea? Frédéric Boucher dziablo@lords.com ^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: One query for two information... @ 2000-04-18 15:31 Moray McConnachie <moray.mcconnachie@computing-services.oxford.ac.uk> parent: Ed <dziablo@lords.com> 0 siblings, 0 replies; 2+ messages in thread From: Moray McConnachie @ 2000-04-18 15:31 UTC (permalink / raw) To: Ed <dziablo@lords.com>; pgsql-sql create function boolint (bool) RETURNS int4 AS 'SELECT CASE WHEN $1=''false'' THEN 0 ELSE 1 END;' LANGUAGE 'sql'; SELECT SUM(boolint(fieldname)) FROM tablename; note double single quote in 2nd line. Yours, Moray ---------------------------------------------------------------- Moray.McConnachie@computing-services.oxford.ac.uk ----- Original Message ----- From: "Ed" <dziablo@lords.com> To: "pgsql sql" <pgsql-sql@postgresql.org> Sent: Tuesday, April 18, 2000 3:26 PM Subject: [SQL] One query for two information... Hi, I have a table containing only a bool filed. I would like to know how many records there is an on many ar true. Is there something I could do to get both answer in only one query... like : select count(*), sum(bool_col) from tablename but there is no sum(bool) function that would add 1 if it's true and 0 if it's false... ;( Any idea? Frédéric Boucher dziablo@lords.com ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2000-04-18 15:31 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2000-04-18 14:26 One query for two information... Ed <dziablo@lords.com> 2000-04-18 15:31 ` Moray McConnachie <moray.mcconnachie@computing-services.oxford.ac.uk>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox