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

SUM(condition) in Oracle?

I’m just curious: I know something like

SUM(string = 'anyString') over (partition by ANY_COLUMN)

or

SUM(string like 'anyWildcard%') over (partition by ANY_COLUMN)

is working in MySQL/MariaDB. What would be the equivalent in Oracle?

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

>Solution :

The ANSI/ISO SQL standard way is to use case expressions to do conditional aggregation:

SUM(case when string = 'anyString' then 1 else 0 end) over (partition by ANY_COLUMN)

Standards compliance note:

Using a case expression is Core SQL functionality, i.e. expected to work on any dbms.

FILTER is an optional feature of the ANSI/ISO SQL standard. ‘Without Feature T612, “Advanced OLAP operations”, conforming SQL language shall not contain a < filter clause >.

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