How do I use Group By based on a Case statement in Oracle?

前端 未结 3 1057
情深已故
情深已故 2020-12-31 02:11

I have an SQL-query where I use Oracle CASE to compare if a date column is less than or greater than current date. But how do I use that

3条回答
  •  情话喂你
    2020-12-31 02:24

    select
    (case
        when exp_date > sysdate then 1
        when exp_date <= sysdate then 2
        else 3
     end) expired, count(*)
    from mytable
    group by (case
        when exp_date > sysdate then 1
        when exp_date <= sysdate then 2
        else 3
     end)
    

提交回复
热议问题