Re: Q: using generate_series to fill in the blanks

From: Rodrigo De León <rdeleonp(at)gmail(dot)com>
To: "Ow Mun Heng" <Ow(dot)Mun(dot)Heng(at)wdc(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Q: using generate_series to fill in the blanks
Date: 2007-12-07 04:06:56
Message-ID: a55915760712062006j352dd5f7scd45faf18a7e288b@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Dec 6, 2007 10:44 PM, Ow Mun Heng <Ow(dot)Mun(dot)Heng(at)wdc(dot)com> wrote:
> I've got a desired output which looks something like this..
>
> vdt | count
> ------------+-------
> 1 | 514
> 2 | 27
> 3 | 15
> 4 | <NULL>
> 5 | 12
> 6 | 15

SELECT i.i AS vdt,
CASE
WHEN COUNT(vdt)=0 THEN NULL
ELSE COUNT(vdt)
END AS COUNT
FROM generate_series (1, 7) i
LEFT JOIN footable f ON i.i = f.vdt AND c_id = '71'
GROUP BY i.i
ORDER BY i.i;

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ow Mun Heng 2007-12-07 05:18:13 Re: Q: using generate_series to fill in the blanks
Previous Message Ow Mun Heng 2007-12-07 03:44:24 Q: using generate_series to fill in the blanks