一张表,里面有  id  name   state    customerid 4个字段,其中status有3个值0 1 2 ,用一条sql查询出此种格式

customerid  state-0   state-1  state-2 
001              11          212        333 
002              15          545        3 

sql如下:

select customid,  
    count(case status when 0 then status else null end) as status-0,  
    count(case status when 1 then status else null end) as status-1,  
    count(case status when 2 then status else null end) as status-2  
    from custom group by customid.  
 

 

相关文章:

  • 2021-04-13
  • 2021-06-14
  • 2021-12-11
  • 2021-12-12
  • 2021-10-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-03
  • 2022-01-30
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案