网上转的,挺经典的

 pid   pnum   sid  
  
1     10     1  
  
1     12     2  
  
2     8      3  
  
3     11     1  
  
3     10     3  
 写一个查询语句使其表现为:  
 pid  s1id  s2id  s3id  
 
1    10     12    0  
 
2    0      0     8  
 
3    11     0     10  
   
 解决办法:  
 
select pid,  
    
sum(case when sid =1 then pnum else 0 endas 's1id',  
    
sum(case when sid =2 then pnum else 0 endas 's2id',  
    
sum(case when sid =3 then pnum else 0 endas 's3id'  
 
from xyz(表名)  
 
group by pid   
 
order by pid  

相关文章:

  • 2021-10-04
  • 2022-02-08
  • 2021-06-02
  • 2022-12-23
  • 2021-12-18
  • 2021-06-13
  • 2021-06-03
  • 2021-10-11
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-07
  • 2021-12-06
  • 2022-12-23
  • 2021-11-06
相关资源
相似解决方案