求 MS-SQL server 数据一条语句

penfly2003 2007-12-25 01:39:05
数据表如下:
表名:Stuinf

学号 姓名 成绩
1 张三 70
3 李四 75
4 王五 72


求奇数行成绩的总分是多少?


Sql语句该怎么写?请各位高手帮忙!
...全文
64 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
rouqu 2007-12-25
  • 打赏
  • 举报
回复
% = 1
JL99000 2007-12-25
  • 打赏
  • 举报
回复
绝对正确
哈哈
JL99000 2007-12-25
  • 打赏
  • 举报
回复
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
echiynn 2007-12-25
  • 打赏
  • 举报
回复

--SQL Server 2000
select id = identity(1, 1), *
into #tmp
from Stuinf
order by 学号

select sum(成绩)
from #tmp
where id % 2 = 1

drop 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
pt1314917 2007-12-25
  • 打赏
  • 举报
回复

select id=itentity(int,1,1),* into #temp from stuinf
select sum(成绩) from #temp where id%2=1
-狙击手- 2007-12-25
  • 打赏
  • 举报
回复
select identity(int,1,1) as id,* into # from stuinf

select 姓名,avg(成绩)
from #
where id%2 =1
gruop by 姓名
fa_ge 2007-12-25
  • 打赏
  • 举报
回复
where 学号%2=1

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧