Oracle sql to count instances of different values in single column

前端 未结 2 941
自闭症患者
自闭症患者 2020-12-04 00:48

I have a table with status column. I want an Oracle sql query which will list me count of rows in each status in only one row. for eg if my table is

Table A
         


        
2条回答
  •  一个人的身影
    2020-12-04 01:09

    select fkey,
           sum(case when status = 20 then 1 else 0 end) as count_status20,
           sum(case when status = 30 then 1 else 0 end) as count_status30,
           sum(case when status = 40 then 1 else 0 end) as count_status40,
    from your_table
    group by fkey
    

提交回复
热议问题