Subject Re: [firebird-support] This SQL conundrum is breaking my head
Author Arno Brinkman
Hi,

<snip>
> I ran the SQL above in DBWB. The first (1.) worked fine (changing
> ActionTaken to ActionCode); the second (2.), though (slightly modified to
> reflect the actual name of the column (ActionCode) and its contents)...
>
> SELECT
> a.gender,
> SUM(CASE a.ActionCode = 1 THEN 1 ELSE 0 END) AS Hired,
> SUM(CASE a.ActionCode = 2 THEN 1 ELSE 0 END) AS NotInterviewed,
> SUM(CASE a.ActionCode = 3 THEN 1 ELSE 0 END) AS Interviewedjobdeclined,
> SUM(CASE a.ActionCode = 4 THEN 1 ELSE 0 END) AS Didnotmeetqualifications
> FROM
> HR_Applicants a
> GROUP BY
> a.gender
>
> ...gives the err msg:
>
> Error code -104, token unknown, =

Sorry, forgotten the WHEN

SELECT
a.gender,
SUM(CASE WHEN a.ActionCode = 1 THEN 1 ELSE 0 END) AS Hired,
SUM(CASE WHEN a.ActionCode = 2 THEN 1 ELSE 0 END) AS NotInterviewed,
SUM(CASE WHEN a.ActionCode = 3 THEN 1 ELSE 0 END) AS Interviewedjobdeclined,
SUM(CASE WHEN a.ActionCode = 4 THEN 1 ELSE 0 END) AS Didnotmeetqualifications
FROM
HR_Applicants a
GROUP BY
a.gender

Regards,
Arno Brinkman
ABVisie

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Firebird open source database (based on IB-OE) with many SQL-99 features :
http://www.firebirdsql.org
http://www.firebirdsql.info
http://www.fingerbird.de/
http://www.comunidade-firebird.org/

Support list for Interbase and Firebird users :
firebird-support@yahoogroups.com

Nederlandse firebird nieuwsgroep :
news://newsgroups.firebirdsql.info