Re: Counting booleans for two columns

From: Thom Brown <thombrown(at)gmail(dot)com>
To: "Oliveiros C," <oliveiros(dot)cristina(at)marktest(dot)pt>
Cc: Rikard Bosnjakovic <rikard(dot)bosnjakovic(at)gmail(dot)com>, pgsql-novice(at)postgresql(dot)org
Subject: Re: Counting booleans for two columns
Date: 2009-11-20 15:11:42
Message-ID: bddc86150911200711s692ab4fds3c2b9b2ec395717a@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

2009/11/20 Oliveiros C, <oliveiros(dot)cristina(at)marktest(dot)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

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Rikard Bosnjakovic 2009-11-20 16:18:29 Re: Counting booleans for two columns
Previous Message Oliveiros C, 2009-11-20 15:06:33 Re: Counting booleans for two columns