1.
select distinct name,
       first_value(month) over(partition by name order by money) min_month,
       first_value(month) over(partition by name order by money desc) max_month,
       (max(money) over(partition by name) - min(money) over(partition by name)) money
from table12.
select distinct month,
       first_value(name) over(partition by month order by money) min_name,
       first_value(name) over(partition by month order by money desc) max_name,
       (max(money) over(partition by month) - min(money) over(partition by month)) money
from table1

解决方案 »

  1.   

    不好意思,如果再加几个字段呢,车间,年份name,chejian,year,month,money
    张三  1,2002,1,100.33
    张三 1,2002,2, 200。22
    张三 1,2002,3, 300。22
    ...
    李四 1,2002,1,300。66
    李四 1,2002,2,300。66
    李四 1,2002,3,412。66
    选出某个车间,每年,每个月金额相差最大的两个人,并显示金额
    ---有可能是空值(比如张三5月没有记录)....
      

  2.   

    结果如下形式
    chejian1,1995,1,张三,李四,100。11
    chejian1,1995,2,王武,赵六,30。11
    chejian1,1995,2,王武,李四,30。11
      

  3.   

    稍微改改就可以了,把分区语句改成按车间,年,月分区
    2.
    select distinct chejian,year,month,
           first_value(name) over(partition by chejian,year,month order by money) min_name,
           first_value(name) over(partition by chejian,year,month order by money desc) max_name,
           (max(money) over(partition by chejian,year,month) - min(money) over(partition by chejian,year,month)) money
    from table1