测试数据
ID              TIME               VALUE
1            2009-01-01             11
1            2009-02-01             12
1            2009-03-01             13
1            2009-04-01             14
2            2009-05-02             15
2            2009-01-01             16
3            2009-02-01             17
2            2009-03-01             18
2            2009-04-01             19
3            2009-05-02             22
3            2009-05-02             21
3            2009-05-02             23
我现在想按ID号来统计 2009-01-01到2009-05-02 VALUE的平均值(2009-01-01的VALUE 减去 2009-05-02的VALUE)这个语句怎么写啊。

解决方案 »

  1.   

    select id,avg(value) 
    from table
    where time between '2009-01-01' and '2009-05-02'
    group by id
      

  2.   

    select id,avg(value)
    from tbname
    where time between '2009-01-01' and '2009-05-02'
    group by id
      

  3.   

    晕。。居然忘记AVG函数了。。
      

  4.   

    select id , avg(value*1.0) avg_value
    from tb
    where time between '2009-01-01' and '2009-05-02'
    grup by id
      

  5.   

    select id , avg(value*1.0) avg_value
    from tb
    where time between '2009-01-01' and '2009-05-02'
    group by id
      

  6.   

    (2009-01-01的VALUE 减去 2009-05-02的VALUE)这个是什么。