Hi
Some days ago I posted a problem with a query.
Thaks to Dave and John, I got a little closer to a solution.
Their suggestion was a solution to my problem as I stated it, but the real
problem is a bit more complicated, so I have to expand the original problem
a bit.
The query has to handle unknown number of departments, and a date interval.
I want:
1) For each day, for each department: a list of (from at_work table) all
employees at work.
2) In the same list I want listed (from emp table) all emplyees that belongs
to this department, but is not on work this date
Here are new scripts:
create table emp
(
empno int not null,
depno int not null
)
alter table emp add primary key (empno)
create table at_work
(
empno int not null,
depno int not null,
working_date int not null,
duration int not null
)
alter table at_work add primary key (empno, depno, working_date)
alter table at_work add constraint fk_at_work_emp foreign key (empno)
references emp (empno)
insert into emp (empno, depno) values (1,10)
insert into emp (empno, depno) values (2,10)
insert into emp (empno, depno) values (3,20)
insert into emp (empno, depno) values (4,20)
insert into at_work (empno, depno, working_date, duration) values
(1,10,'20031017 ',5)
insert into at_work (empno, depno, working_date, duration) values
(3,10,'20031017 ',4)
insert into at_work (empno, depno, working_date, duration) values
(1,10,'20031018 ',6)
insert into at_work (empno, depno, working_date, duration) values
(4,10,'20031018 ',7)
insert into at_work (empno, depno, working_date, duration) values
(1,20,'20031017 ',3)
insert into at_work (empno, depno, working_date, duration) values
(3,20,'20031017 ',5)
insert into at_work (empno, depno, working_date, duration) values
(2,20,'20031018 ',6)
insert into at_work (empno, depno, working_date, duration) values
(3,20,'20031018 ',7)
insert into at_work (empno, depno, working_date, duration) values
(4,20,'20031018 ',8)
The result set should now look like this:
empno depno working_date duration
---------------------------------------------
1 10 '20031017' 5
3 10 '20031017' 4
2 10 '20031017' NULL
1 10 '20031018' 6
4 10 '20031018' 7
2 10 '20031018' NULL
1 20 '20031017' 3
3 20 '20031017' 5
4 20 '20031017' NULL
2 20 '20031018' 6
3 20 '20031018' 7
4 20 '20031018' 8
Could someone please help me?
Thanks in advance
Regards,
Gunnar Vøyenli
EDB-konsulent as
NORWAY
Some days ago I posted a problem with a query.
Thaks to Dave and John, I got a little closer to a solution.
Their suggestion was a solution to my problem as I stated it, but the real
problem is a bit more complicated, so I have to expand the original problem
a bit.
The query has to handle unknown number of departments, and a date interval.
I want:
1) For each day, for each department: a list of (from at_work table) all
employees at work.
2) In the same list I want listed (from emp table) all emplyees that belongs
to this department, but is not on work this date
Here are new scripts:
create table emp
(
empno int not null,
depno int not null
)
alter table emp add primary key (empno)
create table at_work
(
empno int not null,
depno int not null,
working_date int not null,
duration int not null
)
alter table at_work add primary key (empno, depno, working_date)
alter table at_work add constraint fk_at_work_emp foreign key (empno)
references emp (empno)
insert into emp (empno, depno) values (1,10)
insert into emp (empno, depno) values (2,10)
insert into emp (empno, depno) values (3,20)
insert into emp (empno, depno) values (4,20)
insert into at_work (empno, depno, working_date, duration) values
(1,10,'20031017 ',5)
insert into at_work (empno, depno, working_date, duration) values
(3,10,'20031017 ',4)
insert into at_work (empno, depno, working_date, duration) values
(1,10,'20031018 ',6)
insert into at_work (empno, depno, working_date, duration) values
(4,10,'20031018 ',7)
insert into at_work (empno, depno, working_date, duration) values
(1,20,'20031017 ',3)
insert into at_work (empno, depno, working_date, duration) values
(3,20,'20031017 ',5)
insert into at_work (empno, depno, working_date, duration) values
(2,20,'20031018 ',6)
insert into at_work (empno, depno, working_date, duration) values
(3,20,'20031018 ',7)
insert into at_work (empno, depno, working_date, duration) values
(4,20,'20031018 ',8)
The result set should now look like this:
empno depno working_date duration
---------------------------------------------
1 10 '20031017' 5
3 10 '20031017' 4
2 10 '20031017' NULL
1 10 '20031018' 6
4 10 '20031018' 7
2 10 '20031018' NULL
1 20 '20031017' 3
3 20 '20031017' 5
4 20 '20031017' NULL
2 20 '20031018' 6
3 20 '20031018' 7
4 20 '20031018' 8
Could someone please help me?
Thanks in advance
Regards,
Gunnar Vøyenli
EDB-konsulent as
NORWAY
Comment