From: | "Wilkinson, Jim" <Jim(dot)Wilkinson(at)cra-arc(dot)gc(dot)ca> |
---|---|
To: | <pgsql-sql(at)postgresql(dot)org> |
Cc: | "Wilkinson, Jim" <Jim(dot)Wilkinson(at)cra-arc(dot)gc(dot)ca> |
Subject: | How too select different views using a IF/THEN/ELSE procedure ? |
Date: | 2007-03-28 19:04:30 |
Message-ID: | 7CCC5BEF5E72394C963E529B54EB4A642A199E@SD01ITMV12.PROD.NET |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Sumeet | 2007-03-28 20:59:24 | Track query status |
Previous Message | Ray Madigan | 2007-03-28 16:25:17 | Rules with sequence columns |