Re: SELECT counts

From: Tim Landscheidt <tim(at)tim-landscheidt(dot)de>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: SELECT counts
Date: 2010-07-21 11:17:37
Message-ID: m3bpa1ulri.fsf@passepartout.tim-landscheidt.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

"A. Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com> wrote:

> [...]
> test=*# select foo.status_v, count(myt.status_v) from myt right join (select unnest(array['I','P','X']) as status_v) foo on foo.status_v=myt.status_v group by foo.status_v;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> status_v | count
> ----------+-------
> X | 0
> I | 1
> P | 2
> (3 rows)

You can also write this as "(VALUES ('I'), ('P'), ('X')) AS
foo (status_v)" which I personally find more readable (con-
stant vs. function).

Tim

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message A. Kretschmer 2010-07-21 11:27:05 Re: SELECT counts
Previous Message A. Kretschmer 2010-07-21 09:51:37 Re: SELECT counts