select      e.time,    sum(t.tx), sum(ch.rx) ,sum(c.ec) 
from         ("Event"    as e  
left  join   "TXPC"     as t    on  e.oid=t.the_event 
left  join   "Channel+" as ch   on  e.oid=ch.the_event 
left  join    "Cell+"   as c    on  e.oid=c.the_event and c.number=276) 
group  by e.time
having sum(t.tx) is not null or sum(ch.rx) is not null or sum(c.ec) is not null
以上一段程序得出的结果如下:
time  sum(t.tx)  sum(ch.rx)   sum(c.ec)
20:17    -9         -8          null
20:18    -10        null        -20
20:19    14         20           19
20:20    null       null         0      
....要求:得出一个值:当(sum(t.tx)<20 或为空值 and sum(ch.rx)>-95 and sum(c.ec)>-15)的行数除以总行数以原来语句上面加要怎么写呢?谢谢大家了

解决方案 »

  1.   

    select 
    case when (a<20 or a is null) and b>-95 and c>-15 then 1 else 0 end*1.0/count(*) as 结果
    from (
    select      e.time,    sum(t.tx) as a, sum(ch.rx) as b,sum(c.ec) as c
    from         ("Event"    as e  
    left  join   "TXPC"     as t    on  e.oid=t.the_event 
    left  join   "Channel+" as ch   on  e.oid=ch.the_event 
    left  join    "Cell+"   as c    on  e.oid=c.the_event and c.number=276) 
    group  by e.time
    having sum(t.tx) is not null or sum(ch.rx) is not null or sum(c.ec) is not null
    ) as t
      

  2.   

    用Haiwer(海阔天空) 的方法有語法錯誤?
      

  3.   

    最后面 as t 是什么意思?
      

  4.   

    我在查詢分析器裏面沒有檢查出他的語句有問題...最後的as t是為你之前的select語句執行得到的結果集取的一個別名
      

  5.   

    那这个集的别名在前面的select case when中没有被用到啊