本帖最后由 liucongjun666 于 2011-02-16 13:50:10 编辑

解决方案 »

  1.   

    一个小时时间间段内a,b,c的平均值?
    整个小时内a,b,c的平均值?
    和解?
      

  2.   

    如果这个小时内有ff为1的记录则是这个小时时间段内ff为1的平均值,如果整个小时ff都为0,则取整个小时的平均值
      

  3.   


    select convert(varchar(13),riqi,120) as rq,avg(a),avg(a),avg(a)
           from tb where ff=1 group by convert(varchar(13),riqi,120)
    union 
    select convert(varchar(13),riqi,120) as rq,avg(a),avg(a),avg(a)
           from tb a where not exsits
          (select 1 from tb 
             where convert(varchar(13),riqi,120)=convert(varchar(13),a.riqi,120)
               and ff=1)