select a.value+b.value
from (
select id,value from 表 where (id-1) % 2 =0
) a inner join (
select id,value from 表 where (id-1) % 2 =1
) b on a.id=b.id-1

解决方案 »

  1.   

    select sum(value),(id+1)/2
    from your table
    group by (id+1)/2
      

  2.   

    select (id-1)/2+1,sum(bb.value) from 表 bb group by (id-1)/2
      

  3.   

    --1.创建一个合并的函数
    ALTER  function f_sum(@id int)
    returns int
    as
    begin
    declare @str int
    set @str=0
    select @str=@str+ value from 表 where id between @id and @id +2  -- 相邻三个
    return(@str)
    End调用自定义函数得到结果
    select distinct id,dbo.f_sum(id) from 表
      

  4.   

    如果不ID字段并不存在呢先用 select identity(int,1,1) as id,value into #tmp from 表  建一个ID字段
    再对#tmp进行如上操作。
      

  5.   

    更正一下:select (max(id)-1)/2+1,sum(bb.value) from 表 bb group by (id-1)/2
      

  6.   

    如果ID字段不存在,需先创建一个ID字段,然后---
    select identity(int,1,1) as newcol ,* into #www from table
      

  7.   

    如果你要显示编号,就用select b.id/2 as value,a.value+b.value as value
    from (
    select id,value from 表 where (id-1) % 2 =0
    ) a inner join (
    select id,value from 表 where (id-1) % 2 =1
    ) b on a.id=b.id-1
      

  8.   

    如果你要显示编号,就用select b.id/2 as value,a.value+b.value as value
    from (
    select id,value from 表 where (id-1) % 2 =0
    ) a inner join (
    select id,value from 表 where (id-1) % 2 =1
    ) b on a.id=b.id-1
      

  9.   

    如果id字段不存在,就用一个临时表表解决.select id=identity(int,0,1),value into #tb from 你的表select a.id/2+1 as value,a.value+b.value as value
    from (
    select id,value from #tb where (id) % 2 =0
    ) a inner join (
    select id,value from #tb where (id) % 2 =1
    ) b on a.id=b.id-1drop table #tb
      

  10.   

    如果id字段不存在,就用一个临时表表解决.select id=identity(int,0,1),value into #tb from 你的表select a.id/2+1 as value,a.value+b.value as value
    from (
    select id,value from #tb where (id) % 2 =0
    ) a inner join (
    select id,value from #tb where (id) % 2 =1
    ) b on a.id=b.id-1drop table #tb
      

  11.   

    access数据库中,如果没有id的话,就用模块来实现:
      

  12.   

    ACCESS这样也可以吧.select (max(id)-1)/2+1,sum(bb.value) from 表 bb group by (id-1)/2