Re: Counting booleans for two columns - Mailing list pgsql-novice

From Thom Brown
Subject Re: Counting booleans for two columns
Date
Msg-id bddc86150911200711s692ab4fds3c2b9b2ec395717a@mail.gmail.com
Whole thread Raw
In response to Re: Counting booleans for two columns  ("Oliveiros C," <oliveiros.cristina@marktest.pt>)
Responses Re: Counting booleans for two columns  (Rikard Bosnjakovic <rikard.bosnjakovic@gmail.com>)
List pgsql-novice
2009/11/20 Oliveiros C, <oliveiros.cristina@marktest.pt>
SELECT sum(played::integer), sum(stats_exists::integer)
FROM matches
WHERE origin=1 AND stats_exists AND NOT training AND match_date > '2009-08-01';
 
Your approach is elegant, Thom.
 
But if it is to do it that way then I guess
you should drop the "AND stats_exists" part of the query because
it will filter out every line with stats_exists == f, and those (occasionally) played== t won't get summed up  by the SUM() function,
ain't I right ?
 
Best,
Oliveiros
 
Yes, you're right. :) To be honest I didn't really pay much attention to the content of the WHERE clause.  I just tacked it on the end from one of the original selects, but I agree that it should be removed.  So we'd end up with:

SELECT sum(played::integer), sum(stats_exists::integer)
FROM matches
WHERE origin=1 AND NOT training AND match_date > '2009-08-01';

Thom

pgsql-novice by date:

Previous
From: "Oliveiros C,"
Date:
Subject: Re: Counting booleans for two columns
Next
From: Rikard Bosnjakovic
Date:
Subject: Re: Counting booleans for two columns