Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

How too select different views using a IF/THEN/ELSE procedure ?



Title: How too select different views using a IF/THEN/ELSE procedure ?

Below is  a select statement that select incidents by month.   I need a function or a method to select differents views that will show the Month columns is a different  order.  Say Apr Mar for a fiscal year.

I need to do something like an if/then/else statement that selects the correct view to use by a variable check.

Any ideas what I can use or do ?



select case public.incident.gender_code_id

        WHEN 31 THEN 'Male'

        WHEN 32 THEN 'Female'

        ELSE 'Non-Person'

        END,

        count (case extract ( month from public.incident.incident_date )WHEN 01 then 1 Else NULL END) as Jan,

        count (case extract ( month from public.incident.incident_date )WHEN 02 then 1 Else NULL END) as Feb,

        count (case extract ( month from public.incident.incident_date )WHEN 03 then 1 Else NULL END) as Mar,

        count (case extract ( month from public.incident.incident_date )WHEN 04 then 1 Else NULL END) as Apr,

        count (case extract ( month from public.incident.incident_date )WHEN 05 then 1 Else NULL END) as May,

        count (case extract ( month from public.incident.incident_date )WHEN 06 then 1 Else NULL END) as Jun,

        count (case extract ( month from public.incident.incident_date )WHEN 07 then 1 Else NULL END) as Jul,

        count (case extract ( month from public.incident.incident_date )WHEN 08 then 1 Else NULL END) as Aug,

        count (case extract ( month from public.incident.incident_date )WHEN 09 then 1 Else NULL END) as Sep,

        count (case extract ( month from public.incident.incident_date )WHEN 10 then 1 Else NULL END) as Oct,

        count (case extract ( month from public.incident.incident_date )WHEN 11 then 1 Else NULL END) as Nov,

        count (case extract ( month from public.incident.incident_date )WHEN 12 then 1 Else NULL END) as Dec,

        count (extract ( month from public.incident.incident_date )) as Total

from public.incident

GROUP BY public.incident.gender_code_id



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group