Re: Do I just not understand count()

From: Clinton Adams <clinton(at)vote-smart(dot)org>
To: Ben <bench(at)silentmedia(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Do I just not understand count()
Date: 2002-04-08 16:49:20
Message-ID: 20020408185126.022E347589D@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> If I have the table t defined as:
>
> a
> ---
> 1
> 1
> 2
>
>
> and I say:
>
> select count(a=1) from t;
>
> should it give me 1 or 2 as a result? I'm getting 2, and I'd think I
> should get 1....
It will give you a result of 3, as a=1 does not toss out rows for which a <>
1.

You would need to add some parameters to limit the rows that count is
countin...
select count(a) from t where a = 1
would give you 2

select count(DISTINCT a) from t where a = 1
would give you 1

>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2002-04-08 16:56:18 Re: Tcl_CreateSlave error (pg 7.1.2, RH 7.2)
Previous Message Stephan Szabo 2002-04-08 16:45:09 Re: retun cursor