[/color][color=darkred][color=darkred][/color]
问题: 这个问题是有Jim chupella 在CompuServe上的MS Access论坛上提出的。 他需要创建一个记录雇员缺勤率的数据库。使用的表
create table Absenteeism (
emp_id integer not null references personel(emp_id),
absent_date date not null,
reason_code varchar2(40) not null references ExcuseList(reason_code),
severity_points integer not null check(severity_points between 1 and 4),
primary key(emp_id,absent_date)
);
雇员的id号用来标识每个雇员。 reason_code是相关缺勤记录原因的简短文本描述(例如,被运送啤酒的卡车撞了,;今天不顺利,心情很糟糕,等等),它来自于一个不断增加增加的虚构列表。严重性积分severity_points)时候一个计分系统,对缺勤行为进行处罚性计分。
如果雇员在一年的时间内严重性计分累计达到40分,就自动将该雇员解雇。 如果雇员连续缺勤超过一个天,就视为长病假, 而不是普通的缺勤。这时候第二天、第三天和以后的日子都
不会统计该雇员的严重性分数,这些天也不算做缺勤。
你的工作是编写实施的这两个业务规则的SQL, 如果需要也可以该模式
解答:看一看解雇员工的第一条规定, 最常见的设计错误是试图从表中删除第二、三天以及以后的天数。 这个方法使计算天数的查询变得混乱, 并很难查找从表中连续的病假
。
首先要更改严重性惩罚分数(severity_points)可以为0, 这样可以使Absenteeism表中的记录雇员的长病期。只需要将severity_points改为check( severity_points between 0 and 4)
step1.创建一个Personel员工表
create table personel(
emp_id integer not null primary key,
emp_name varchar2(40) not null
);
create sequence personel_sequence
increment by 1
start with 1
nomaxvalue
nocycle
cache 10;
引用
//alter table personel add constraints PK_personel_emp primary key(emp_id);
insert into personel values(personel_sequence.nextval,'liaobinxu');
insert into personel values(personel_sequence.nextval,'fenerdong');
insert into personel values(personel_sequence.nextval,'孙翔');
insert into personel values(personel_sequence.nextval,'谢江');
step2.创建一个ExcuseList原因执行表
create table ExcuseList(
reason_code varchar2(40) primary key not null,
effective_date date not null
);
//表已经创建
insert into ExcuseList values('long term illness','01-1月-2009');
insert into ExcuseList values('absentess','01-1月-2009');
insert into ExcuseList values('on a bussiness trip','01-1月-2009');
commit;
step3.创建一个缺勤表
create table Absenteeism (
emp_id integer not null references personel(emp_id) on delete cascade,
absent_date date not null,
reason_code varchar2(40) not null references ExcuseList(reason_code),
severity_points integer not null check(severity_points between 0 and 4),
primary key(emp_id,absent_date)
);
由于在开除员工,为让倚赖它的表产生数据统一性,必须在emp_id上加入 on delete cascade, 修改severity_points的check约束 在0,4之间, 不管用alter table absenteeism modify (severity_points integer check(severity_points between 0 and 4));
插入数据
使用了insert into table_name (col_1,col2,...) (select col_1 ,select col_2 from (select col_1,col_2 from table_nam2 ))
由于absenteeism表没有数据,而且插入的数据与时间有关系。absenteeism中emp_id来来自personel表的emp_id,absent_date于时间有关系(要求absent_date不能在同一个用户产生的相同的日期),reason_code来自ExcusteList表中,severity_points是在0和4之间的整数
create or replace procedure proc_Absenteeism_insert
as
start_date date;
begin
start_date:=sysdate;
for i in 0..9999
loop
insert into
Absenteeism (emp_id,absent_date,reason_code,severity_points)
(
select emp_id ,insdate,reason_code,spoints
from (
select p.emp_id,to_date('1-3-2009','dd-mm-yyyy')+i insdate,
e.reason_code ,
trunc(dbms_random.value(0,5)) spoints
from
personel p ,ExcuseList e
order by dbms_random.value
)
where rownum<2
);
end loop;
end;
//执行procedure
exec proc_absenteeism_insert;
引用
用时6秒
step4. 更改长病期和删除超过40分的雇员
更新数据要求连续两次或这迟到两次以上视为病假,并且为长病假,而不是普通的缺勤。
一个相同的表使用子查询 a1.id=a2.id 关联起来, 然后使用‘第二天、第三天和以后的日子都不会统计该雇员的严重性分数’ 条件, 即是’每个人前后相差一天‘
update absenteeism a1
set severity_points=0,
reason_code='long term illness'
where exists
(select * from absenteeism a2 where a1.emp_id=a2.emp_id and a1.absent_date-1=a2.absent_date);
已经更新2478行
由于插入数据时概率过大,把严重性惩罚分数40, 改为130分
delete * from personel where emp_id in(
select emp_id from absenteeism where absent_date between sysdate and
add_months(sysdate,12) group by emp_id having
sum(severity_points)>=130
);
分享到:
相关推荐
SQL案例专题-缺勤者.pdf
参考资料-缺勤处理方法.zip
Excel表格+Word文档各类各行业模板-缺勤处理办法.doc
Excel表格+Word文档各类各行业模板-缺勤处理办法.zip
3.学生-缺勤记录 4.学生-修改密码 5.宿舍管理员-主页面 6.宿舍管理员-学生查看 7.宿舍管理员-缺勤记录 8.系统管理员-宿舍管理员管理 9.系统管理员-学生管理 10.系统管理员-宿舍楼管理 11.系统管理员-缺勤记录 详情...
3.学生-缺勤记录 4.学生-修改密码 5.宿舍管理员-主页面 6.宿舍管理员-学生查看 7.宿舍管理员-缺勤记录 8.系统管理员-宿舍管理员管理 9.系统管理员-学生管理 10.系统管理员-宿舍楼管理 11.系统管理员-缺勤记录 详情...
│ │ 3.6.4 动态他Transact-SQL语句处理中的常见问题演示.sql │ │ 3.7.3 text与ntext字段的复制和合并处理示例.sql │ │ 3.7.4 text与image字段转换处理示例.sql │ │ 3.7.5 ntext字段的REPLACE处理示例.sql │...
8-11月缺勤数据.rar
缺勤是世界上的一项重要实践,因为工人在工作场所的持续存在对实现任何部门或机构的目标至关重要。 结果,管理层可能无法实现其目标。 因此,本文将通过在Municipal市教育办公室检查此事作为案例分析,从而加深对该...
-列车车次查询.sql │ │ 3.6.2 字符串在编号查询中的应用示例及常见问题.sql │ │ 3.6.3 动态参数的存储过程示例.sql │ │ 3.6.4 动态他Transact-SQL语句处理中的常见问题演示.sql │ │ 3.7.3 ...
与熟练度,半熟练度和非熟练度雇员相比,女性雇员的缺勤率高于男性雇员,而Abd较低,而会计师的缺勤率最低,而专业级雇员缺勤率最高。 与一年中其他时间相比,大部分时间都在9月至12月丢失。 结果表明,FSL中较高的...
WS 357.14-2016学校缺勤缺课监测报告1
及时反映员工的出勤,以及缺勤扣款情况 (2)、员工津贴表,反映员工的加班时间,加班类别、加班天数、津贴情况等 ; (3)、员工基本信息表,反映员工的基本信息,反映员工的工种、等级,基本 工资等信息; (4)、员工月...
缺勤处理办法.zip
美国会计准则中文版10带薪缺勤-reviewedbyCathy-ok.pdf
WS 357.15-2016托幼机构缺勤监测报告1
EXCEL常用模板-人事模板-考勤类到勤缺勤考勤表
(1)管理人员的月工资 = 月薪 - 缺勤天数 × 月薪 ÷ 22; (2)销售人员的月工资 = 底薪 + 销售金额 × 提成比例; (3)计件工人的月工资 = 产品件数 × 每件报酬; (4)计时工人的月工资 = 工作...
3.6.4 动态Transact-SQL语句中常见问题 92 3.7 text与ntext字段处理 96 3.7.1 text与ntext数据的存储 96 3.7.2 管理text与ntext数据 97 3.7.3 text与ntext字段的复制和合并 99 3.7.4 text与image...
缺勤处理方法#1 员工的准时出勤是公司正常运转的必要前提。只有完成生产要求才能满足客户的要求。每一位员工都是这个团体的一分子,要达到目标,就必须保证出勤。缺勤或迟到状况都会被记录在案。 准时:公司希望...