Lukas Eder notes a bit of ANSI SQL:
The following aggregate function computes the number of rows per group which satifsy the
FILTERclause:
SELECTCOUNT(*) FILTER (WHEREBOOK.TITLELIKE'A%'),COUNT(*) FILTER (WHEREBOOK.TITLELIKE'B%'),...FROMBOOKThis is useful for pivot style queries, where multiple aggregate values are computed in one go. For most basic types of aggregate function, it can be emulated simply by using
CASEexpressions, because standard aggregate functions ignoreNULLvalues when aggregating.
Lukas shows how you can also implement this logic using JSON_TRANSFORM() though I think I’d just as soon stick with COUNT(CASE WHEN BOOK.TITLE LIKE 'A%' THEN 1 END) and try hard not to think about shredding JSON.