sql语句问题 - MS-SQL Server / 应用实例
有一个表,存放的是学生的成绩,
完成如下功能:
如果一个学生的某门课程的成绩低于该门课程的平均成绩,将他的成绩提高5%
s_c(sid,cid,score)
sid学号
cid 课程号
score成绩
SQL code:
update s set s.score=1.05*score
from s_c s
join
(select cid,avg(score) as avgscore
from s_c
Group by cid) c on s.cid=c.cid and s.score<c.avgscore
SQL code:
create table s_c(sid int,cid int,score int)
insert s_c
select 1,1,40 union all
select 2,1,50 union all
select 3,1,60 union all
select 1,2,50 union all
select 2,2,60 union all
select 3,2,70
select * from s_c t
where score<(select avg(score) from s_c where cid=t.cid group by cid)
/*
sid cid score
----------- ----------- -----------
1 1 40
1 2 50
(所影响的行数为 2 行)*/
update t set score = score*1.05
from s_c t
where score<(select avg(score) from s_c where cid=t.cid group by cid)
select * from s_c
/*
sid cid score
----------- ----------- -----------
1 1 42
2 1 50
3 1 60
1 2 52
2 2 60
3 2 70
(所影响的行数为 6 行)
*/
相关问答:
可能因为工作的原因 接触数据库这块比较少,之前都是做程序这块,数据库这块都有专门的人来做 分工都很明细 所以对数据库这一块完全不了解。前段时间 去面试了几家公司 几乎都是在数据库这块挂掉的 连个简单的SQ ......
今天做了一个存储过程 环境是SQL2000数据库
大致如下
建立临时表
定义员工游标
循环员工(属于1个公司)
......
sql的软件在哪里可以下啊!在网上找了蛮多都用不了啊
随便搞一D版吧,
迅雷第一个就可以用
2000,2005都这样
http://119.147.41.16/down?cid=0698C2D64D7D637D90A6D2482298E6717D4F15CD&t=2&fmt=-1 ......
我想查询出每天数据的最大的一个值。表的格式如下
表名: hisdata
字段 编号 值 状态 时间
Id value state dattime
101 32.3 0 ......
求个vb中的sql语句的写法,次sql语句的用法是分页程序
我写的如下:其中A是用来接收每页显示的记录的条数,B是用来接收显示的当前的页面.
sqltext="select top A * from log where id not in(select top ( ......