简体   繁体   中英

How to write CASE WHEN COUNT in HANA SQL

The following column gives me counts:

COUNT("COMPLIANCE"."CD_ALL"."ProductCode") As "Active Contracts"

However, I want to put the count totals into buckets. This is what I tried:

case when (COUNT("COMPLIANCE"."CD_ALL"."ProductCode")) between 0 and 10 then '10 or less',

case when (COUNT("COMPLIANCE"."CD_ALL"."ProductCode")) between 11 and 20 then '11-20',

and so on...

What am I doing wrong here?

I think you want a single case expression:

(case when (COUNT("COMPLIANCE"."CD_ALL"."ProductCode")) <= 10 then '10 or less'

      when (COUNT("COMPLIANCE"."CD_ALL"."ProductCode")) <= 20 then '11-20'
      else 'That many!!!'
end) as count_bucket

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM