………………………………………………………………………………………………………………………………………………
>T-SQL 语句的综合应用
select * from stuinfo
select * from stumarks
select 应到人数 = (select count(*) from stuinfo),
实到人数 = (select count(*) from stumarks),
缺考人数 = ((select count(*) from stuinfo) - (select count(*) from stumarks))
if exists (select * from sysobjects where name = ''newtable'')
drop table newtable
select stuname,stuno,writtenexam,labexam,
ispass = case
when writtenexam>60 and labexam>60 then 1
else 0
end
into newtable from stuinfo left join stumarks
on stuinfo.stuno = stumarks.stuno
select * from newtable
declare @avgwritten numeric(4,1),@avglab numeric(4,1)
select @avgwritten = avg(writtenexam) from newtable where writtenexam is not null
select @avglab = avg(labexam) from newtable where labexam is not null
if @avgwritten<@avglab
while(1=1)
begin
update newtable set writtenexam = writtenexam + 1
if (select max(writtenexam) from newtable)>=97
break
end
else
while(1=1)
begin
update newtable set labexam = labexam + 1
if (select max(labexam) from newtable)>=97
break
end
update newtable set ispass = case
when writtenexam>60 and labexam>60 then 1
else 0
&nbs