微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

SqlServer和Oracle中一些常用的sql语句4 局部/全局变量

--把wh1仓库号中姓名含有"平"字的职工工资在原来的基础上加288
update 职工备份 set 工资=工资+288 where 仓库号='wh1' and 姓名 like '%平%'

--把"北京"地区的职工的工资减少100,再增加1倍
update 职工备份 set 工资=(工资-100)*2 where 仓库号 in
   (select 仓库号 from 仓库备份 where 城市='北京')
   
--把面积小于"北京"地区最小面积的仓库面积增加80
update 仓库备份 set 面积=面积+80 where 面积<
  ( select MIN(面积) from 仓库备份 where 城市='北京')
  
--把工资大于不同仓库的所有平均工资的职工的工资减少66  
update 职工备份 set 工资=工资-66 where 工资> all(
   select AVG(工资) from 职工备份 group by 仓库号)

--删除面积最大和最小的仓库信息   
delete 仓库备份 where 面积 in ( 
(select MAX(面积) from 仓库备份),(select min(面积) from 仓库备份)
)
   
--删除工资大于所有职工平均工资的职工信息
delete 职工备份 where 工资> (select AVG(工资) from 职工备份 )

--删除"上海","济南"的所有职工信息
delete 职工备份 where 仓库号 in
    (select 仓库号 from 仓库备份  where 城市 in('上海','济南'))

--局部变量声明 赋值 输出 
declare @str1 char(10),@str2 varchar(50),@x1 int,@x2 real,@time1 datetime
set @str1='good'
set @str2='hello,how are you?'
set @x1=12
set @x2=15
set @time1='2009/05/06'
print @str1
print @str2
print @x1
print @x2
print @time1

--局部变量声明 赋值 输出
declare @str1 char(10),@time1 datetime
select @str1='good',@str2='hello,how are you?',@x1=12,@x2=15,@time1='2009/05/06'
select @str1 as 字符变量1,@str2 as 字符变量2,@x1 as 整型变量1,@x2 as 整型变量2,@time1 as 日期时间变量

--局部变量
declare @x int
set @x=2000
select * from 职工 where 工资>@x

--全局变量
PRINT @@version

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐