我有一张记录每日出勤率的表格。
CREATE TABLE "DAILY_ATTENDANCE" (
"SERIAL_NO" NUMBER(10,0),
"EMPLOYEE_ID" NUMBER(4,0),
"FIRST_NAME" VARCHAR2(100),
"MIDDLE_NAME" VARCHAR2(100),
"LAST_NAME" VARCHAR2(100),
"ATTENDANCE_DATE" DATE,
"STATUS" VARCHAR2(100) DEFAULT 'PRESENT',
"MONTH" VARCHAR2(100),
"YEAR" VARCHAR2(100),
CONSTRAINT "DAILY_ATTENDANCE_PK" PRIMARY KEY ("SERIAL_NO") ENABLE,
CONSTRAINT "DAILY_ATTENDANCE_UK1" UNIQUE ("EMPLOYEE_ID", "ATTENDANCE_DATE")
ENABLE
);
create or replace trigger "DAILY_ATTENDANCE_T5"
BEFORE insert or update on "DAILY_ATTENDANCE"
for each row
begin
:new.month:= to_char(:new.ATTENDANCE_DATE, 'month') ;
:new.year:= to_char(:new.ATTENDANCE_DATE, 'YYYY') ;
end;
我如何编写一个简单的sql语句,该语句提供每月&员工ID和状态的年度分组?状态具有现状,病假等价值。 例如:在2015年的每个月找不到employee_id = 1001拍摄的病假?
答案 0 :(得分:0)
您可以尝试以下查询:
select a.year,a.month,a.employeeId,count(*)
from
(select * from DAILY_ATTENDANCE where status ='sickleave')a
group by a.year,a.month,a.employeeId