为什么2005的返回是2
   2007的返回是0,2008的返回是1?
  看不出什么规律,怎么写sql啊?
  lz应该把问题描述清楚些~~~~~~~~~~~~~~~

解决方案 »

  1.   

    一个sql是搞不定的,你这个需要判断下一年是否比上一年分数高,写个存储过程吧
      

  2.   

    虽然不是通过sql直接得到结果,也是用一个sql语句完成的吗!!呵呵
      

  3.   

    select * from test a,test b where a.score<b.score and a.id<b.id and b.id-a.id=1id          score       id          score       
    ----------- ----------- ----------- ----------- 
    2005        10          2006        20
    2006        20          2007        30
    2008        20          2009        30
    2009        30          2010        40
    2010        40          2011        50根据这个结果去数,当id增量为1时count++,否则return