cube icon indicating copy to clipboard operation
cube copied to clipboard

SQL API failed - sum + case when

Open egisberto opened this issue 1 month ago • 1 comments

Failed SQL SELECT sum(CASE WHEN indicator_nm IN ('[REPLACED]') THEN 1 ELSE 0 END) AS asdf FROM pregnants_view LIMIT 1001

Logical Plan

Version: 0.34.52

Additional context I try to execute this simple query to SUM values and after this make a division by the total values. (percent of certain indicator_nm). I'm using Superset as dashboard creator and thia is the one way that I found to make the percentage works on Superset. (https://docs.preset.io/docs/using-metrics-and-calculated-columns)

The final query wold be:

SELECT (CAST(sum(CASE WHEN indicator_nm = 'odontoCare' THEN 1 ELSE 0 END) AS FLOAT) / CAST(count(1) AS FLOAT)) * 100

egisberto avatar May 29 '24 14:05 egisberto