日期:2014-05-17  浏览次数:20950 次

求语句

有这么一个库
我想 根据serialcode 把它对应的不同的classnumber (3和1)所对应的 branchquantity的值求倍数(classnumber=1的 branchquantity值 除以classnumber=3的 branchquantity值 ) 然后把倍数存到一个临时量中 该怎么做? 

------解决方案--------------------
引用:
临时变量可以先放在一边 我想先求这个倍数


select serialcode,s1/s3
  from (select serialcode, classnumber, branchquantity from  t where t.classnumber in (1,3)) 
  pivot(sum(branchquantity) for classnumber in(1 s1,3 s3))
 where s1 is not null
   and s3 is not null;