【练手】给员工加工资

--给员工加工资,当员工里面有一半的人没有达到6000元的时候,所有员工加100,并打印加了多少工资
--author:【DBA】小七
create  table [#t](id int, name char(10),sal int)  --创建临时表
insert into #t
select 1,'alex',1500 union all
select 2,'kelly',5000 union all
select 3,'lily',10000 union all
select 4,'judy',6000 union all
select 5,'tom',5900 union all
select 6,'cherly',4000 union all
select 7,'cherly',3500 union all
select 8,'romeo',7000 union all
select 9,'frank',5500
select * from #t

go

if Exists(Select name From sysobjects Where name='add_sal' And type='P')
Drop Procedure add_sal
     Go

create proc add_sal
as
begin
set nocount on
declare @count1 float,@count2 int,@up_sal int
set @up_sal=0
set @count1=(select count(*) from #t)
set @count2=(select count(8) from #t where sal<6000)
while(@count2>(@count1/2))
begin
update #t set sal=sal+100
set @count1=(select count(*) from #t)
set @count2=(select count(8) from #t where sal<6000)
set @up_sal=@up_sal+100
end
print  @up_sal
set nocount off
end
go

exec add_sal
go

drop table #t

go

(所影响的行数为 9 行)

id          name       sal         
----------- ---------- -----------
1           alex       1500
2           kelly      5000
3           lily       10000
4           judy       6000
5           tom        5900
6           cherly     4000
7           cherly     3500
8           romeo      7000
9           frank      5500

(所影响的行数为 9 行)

500

--有兴趣可以试试吧6000这个工资改成参数,应该是很简单的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值