日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql编写存储过程给员工加工资_一个增加员工工资的数据库存储过程

發(fā)布時(shí)間:2024/3/26 数据库 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql编写存储过程给员工加工资_一个增加员工工资的数据库存储过程 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

一個(gè)面試問題,寫一個(gè)SQL語句或者存儲(chǔ)過程,給員工加工資,當(dāng)員工里面有一半的人沒有達(dá)到6000元的時(shí)候,所有員工加100,并打印加了多少工資。

存儲(chǔ)過程如下:

--給員工加工資,當(dāng)員工里面有一半的人沒有達(dá)到6000元的時(shí)候,所有員工加100,并打印加了多少工資

create table [#t](id int, name char(10),sal int) --創(chuàng)建臨時(shí)表

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

這個(gè)存儲(chǔ)過程的運(yùn)行結(jié)果如下:

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

(所影響的行數(shù)為 9 行)

500

如果各位有興趣的話,也可以試試吧6000這個(gè)工資改成參數(shù),應(yīng)該是很簡單的。

總結(jié)

以上是生活随笔為你收集整理的mysql编写存储过程给员工加工资_一个增加员工工资的数据库存储过程的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。