我现在有一个表,
 hid      pk, hacc     户号 , htype    分为0 1 两种情况 ,   fCode      基金代码 ,  
  share    成交量(number) ,tdate     成交时间          我用一条sql语句实现以下效果select (count(b.hacc) / count(a.hacc)) reta ,( count(c.hacc) /count(a.hacc)) retb     
from table a, (select * from table where htype = 0) b, (select * from table where htype = 1) 根据fcode查例:hid   hacc   htype   fcode   share   tdate
    1     001    0        0001    20      20080101
    2     002    0        0001    10      20080101
    3     002    1        0001     50      20080101
    4     002    1        0002     60      20080101
结果:0001的  reta=2/3=0.666   retb=1/3=0.333

解决方案 »

  1.   

    这个用一条sql语句咋实现这个效果啊,帮帮忙哈,,,忘提问题了哈严重bs我旁边那个人占sf
      

  2.   

    问的问题看不懂,你的那个sql 到底干什么用的?
      

  3.   


    select   (count(case when b.hacc=0 then 1 else null end )   /   count(a.hacc))   reta   ,
    (   count(case when b.hacc=1 then 1 else null end )   /count(a.hacc))   retb          
    from   table   a,   table  case when then   ..  else end  或者decode
      

  4.   

    好用好用,谢谢大侠请问一下那个
    case   when   then       ..     else   end     或者decode
    是什么啊,以及他的用法,这个有点看不懂
      

  5.   

    仔细看了下,结果retb=0.333没问题  reta=0?应该是0.666 
      

  6.   

    hid       hacc       htype       fcode       share       tdate
    1           001         0        0001         20         20080101
    2           002         0        0001         10         20080101
    3           002         1        0001         50         20080101
    4           002         1        0002         60         20080101 retb=  ( (hid=3,1条)/hid=1,2,3)=0.333
    reta= ( (hid=1,2,1条)/hid=1,2,3)=0.666
    case when ...  就相当于  if else 的语法
    decode也是的,decode(字段,预值1,结果1,预值2,结果2,都不符合的值)