Can anyone help me with the proper syntax for a “case” statement using SQL Plus?
Select
sum(case "REQUEST AGE" when >= 60 then 1 else 0) as "60+ Days",
sum(case "REQUEST AGE" when >= 30 and case when "REQUEST AGE" < 60 then 1 else 0) as "30- 60 Days",
sum (case "REQUEST AGE" when < 30 then 1 else 0) as "Less Than 30 Days",
"SECTOR"
FROM Schema.APPDATA
Where Schema.APPDATA."SECTOR" like '%X%'
I’m relatively new to SQL and I have never written such a query. I would like a sum of a case when the column request age is greater than 60, between 30 and 60 and less than 30 as 3 columns grouped by column sector
You need to use
CASE WHEN [expression]... THENrather thanCASE [variable] WHEN [value] THEN ...:Also, it seems that
countis more appropriate in your case thansum– you won’t needelseat all.