怎么把计算后的数值在插到表中...

ProgramFuny 2006-07-14 04:27:00
一个学生考试成绩的统计表 :主键stuNum 还有两个成绩列如(subject1 ,subject2),现在要计算出均分,在在表后加上一列 用于存储均分,该怎么写呢~~~~
...全文
140 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
小炮叔 2006-07-14
  • 打赏
  • 举报
回复
select *,avg(subject1+subject2) as 平均分 from 学生成绩表
kisa99 2006-07-14
  • 打赏
  • 举报
回复
我的错了,应该是
Select *,(subject1+subject)/2 As 均分 From 学生考试成绩
playwarcraft 2006-07-14
  • 打赏
  • 举报
回复

alter table 统计表 add avgs1_s2 null
update 统计表 set avgs1_s2=(subject1+subject2)/2.0
select * from 统计表
LouisXIV 2006-07-14
  • 打赏
  • 举报
回复
create table test
(
stuNum int,
subject1 int,
subject2 int
)
insert into test
select 1,70,80 union all
select 2,80,94 union all
select 3,60,71

select * from test

alter table test add average as (subject1+subject2)/2

select * from test

go
drop table test

/*
stuNum subject1 subject2
----------- ----------- -----------
1 70 80
2 80 94
3 60 71

stuNum subject1 subject2 average
----------- ----------- ----------- -----------
1 70 80 75
2 80 94 87
3 60 71 65
*/
kisa99 2006-07-14
  • 打赏
  • 举报
回复
select *,avg(subject1+subject2) as 均分 from table
建哥聊IT 2006-07-14
  • 打赏
  • 举报
回复
应该是这样:
create table #tbl(sub1,sub2)
insert #tbl
select subject1,subject2
from 成绩表
uniion all
select avg(subject1),avg(subject2)
from 成绩表
paoluo 2006-07-14
  • 打赏
  • 举报
回复
??

Select *,(subject1+subject)/2 As 均分 From 学生考试成绩
建哥聊IT 2006-07-14
  • 打赏
  • 举报
回复
insert 成绩表
select avg(subject1),avg(subject2)
from 成绩表

34,590

社区成员

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

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