数据表如下:
表名:Stuinf学号   姓名   成绩 
1     张三   70
3     李四   75
4     王五   72
求奇数行成绩的总分是多少?
Sql语句该怎么写?请各位高手帮忙!

解决方案 »

  1.   

    select identity(int,1,1) as id,* into # from stuinfselect 姓名,avg(成绩)
    from #
    where id%2 =1 
    gruop by 姓名
      

  2.   


    select id=itentity(int,1,1),* into #temp from stuinf
    select sum(成绩) from #temp where id%2=1
      

  3.   


    --SQL Server 2000
    select id = identity(1, 1), *
    into #tmp
    from Stuinf
    order by 学号select sum(成绩)
    from #tmp
    where id % 2 = 1drop table #tmp--SQL Server 2005
    select sum(t.成绩)
    from
    (select id = row_number() over(order by 学号), 成绩
    from Stuinf) as t
    where t.id % 2 = 1
      

  4.   

    if object_id('A') is not null
       drop table A
    go
    create table A(学号 int,姓名 varchar(20),成绩 int)
    insert A 
    select 1,           '张三',       70 union all  
    select 3,           '李四',       75 union all 
    select 4,           '王五',       72 
    declare @t table(id int identity(0,1),学号 int,姓名 varchar(20),成绩 int)
    insert @t select * from A
    select sum(成绩) as 奇数行总成绩 from @t where id%2=0