一个面试问题,写一个SQL语句或者存储过程,给员工加工资,当员工里面有一半的人没有达到6000元的时候,所有员工加100,并打印加了多少工资。
存储过程如下:
--给员工加工资,当员工里面有一半的人没有达到6000元的时候,所有员工加100,并打印加了多少工资
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