using sql count in a case statement

前端 未结 8 1458
花落未央
花落未央 2020-12-13 17:29

I have a table and i need to present the output in the following fashion.

tb_a:

col1  |  reg_id | rsp_ind 

Count of rows with rsp_ind = 0

相关标签:
8条回答
  • 2020-12-13 18:11
    SELECT 
        COUNT(CASE WHEN rsp_ind = 0 then 1 ELSE NULL END) as "New",
        COUNT(CASE WHEN rsp_ind = 1 then 1 ELSE NULL END) as "Accepted"
    from tb_a
    

    You can see the output for this request HERE

    0 讨论(0)
  • 2020-12-13 18:11

    The reason you're getting two rows instead of one is that you are grouping by rsp_ind in the outer query (which you did not, to my disappointment, share with us). There is nothing you can do to force one row instead of two without dealing with that GROUP BY item.

    0 讨论(0)
提交回复
热议问题