我的查询语句是这样的:
select S_sampled_date,SP_sampling_point,(sum(decode(R_name,'硫含量',R_value))) as value_lhl from u_sample where  S_sampled_date between to_date('2008-1-1','yyyy-mm-dd') and to_date('2008-5-5','yyyy-mm-dd') and to_char(S_sampled_date,'D') -1 in (1,3,5)  and S_sampling_point_id = 'LYD2_TQYY' group by S_sampled_date,SP_sampling_point  order by  value_lhl desc查询出结果是:
S_sampled_date        SP_sampling_point        value_lhl
2008-1-9                   2#原油                0.2
2008-1-2                   2#原油                0.18   
2008-1-11                  2#原油                0.16
2008-1-4                   2#原油                0.13
2008-1-7                   2#原油                0.06
我的意思是在这个基础上取得最大值,最小值和平均值,根据上面的查询结果应该分别为0.2、0.06、0.146,请问我怎么写oracle语句呢?谢谢帮忙!

解决方案 »

  1.   

    select SP_sampling_point,max(value_lhl),min(value_lhl),avg(value_lhl)
     from
    (select S_sampled_date,SP_sampling_point,(sum(decode(R_name,'硫含量',R_value))) as value_lhl from u_sample where  S_sampled_date between to_date('2008-1-1','yyyy-mm-dd') and to_date('2008-5-5','yyyy-mm-dd') and to_char(S_sampled_date,'D') -1 in (1,3,5)  and S_sampling_point_id = 'LYD2_TQYY' group by S_sampled_date,SP_sampling_point  order by  value_lhl desc) a 
    group by SP_sampling_point
      

  2.   

    楼上正解 建议楼主熟悉下Oracle的一些基本函数