Search Postgresql Archives

Re: Q: using generate_series to fill in the blanks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Dec 6, 2007 10:44 PM, Ow Mun Heng <Ow.Mun.Heng@xxxxxxx> 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;

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

               http://archives.postgresql.org/

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux