SQL加上“case”关键字

SQL加上“case”关键字,sql,Sql,有谁能帮助我使用SQL Plus的case语句的正确语法吗 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 < 3

有谁能帮助我使用SQL Plus的case语句的正确语法吗

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%'
我对SQL相对来说是新手,我从未编写过这样的查询。当列请求期限大于60、介于30和60之间且小于30时,我想要一个case的总和,因为按列扇区分组的3列

每个case语句都必须在。您可以在此处使用CASE-WHEN语法:

Select 
  sum(case when "REQUEST AGE" >= 60 then 1 else 0 END) as "60+ Days",
  /* And in here, don't repeat the CASE keyword. Both parts of the expression are connected by AND */
  sum(case when "REQUEST AGE" >= 30 and "REQUEST AGE" < 60 then 1 else 0 END) as "30-    60 Days",
  sum (case when "REQUEST AGE" < 30 then 1 else 0 END) as "Less Than 30 Days",
  "SECTOR"
FROM Schema.APPDATA
Where Schema.APPDATA."SECTOR" like '%X%'
当[expression]出现时,需要使用CASE。。。然后,当[value]时,而不是CASE[variable],然后…:


此外,在您的情况下,计数似乎比求和更合适-您根本不需要其他答案。

我需要这个以及下一个答案,所以也谢谢您
Select 
sum(case WHEN "REQUEST AGE" >= 60 then 1 else 0 end) as "60+ Days",
....