Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using FILTER in IBM DB2 query

I have some queries which works correctly in PostgreSQL but I have to use them to make IBM DB2 queries. It seems like "FILTER" doesn’t work with DB2.

My PGSQL query :

SELECT CODACT, SUM(CUMCOL) FILTER(WHERE etasup > 20), SUM(CUMCOL)
FROM gesupe WHERE typsup= '1' AND (DATLIV = 20220428 OR DATLIV = 20220429) GROUP BY CODACT

When I use this with DB2 I get this error :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Element '(' not correct. Possible elements : , FROM INTO

>Solution :

In general, it should be possible to rewrite the FILTER into a CASE statement. Something like:

SUM(CASE WHEN etasup > 20 THEN CUMCOL END)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading