A
A
andrenos2020-07-06 12:07:23
SQL
andrenos, 2020-07-06 12:07:23

How to display a list?

-- Справочник сотрудников
create table Employee (
ID int not null primary key,
Code varchar(10) not null unique,
Name varchar(255))
insert into Employee (ID, Code, Name)
values (1, 'E01', 'Ivanov Ivan Ivanovich'),
(2, 'E02', 'Petrov Petr Petrovich'),
(3, 'E03', 'Sidorov Sidr Sidorovich')
-- Отпуска сотрудников
create table Vacation (
ID int not null identity(1, 1) primary key,
ID_Employee int not null references Employee(ID),
DateBegin date not null,
DateEnd date not null)
insert into Vacation (ID_Employee, DateBegin, DateEnd)
values (1, '2019-08-10', '2019-09-01')
,(3, '2019-07-29', '2020-01-14')
,(2, '2019-05-01', '2019-05-15')

You need to display a list of employees who were on vacation at one point in time. Those. if one is on vacation from 01.07 to 15.07, and the other from 08.07 to 23.07. You need to output one line with the names of both employees.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2020-07-06
@andrenos

You do JOIN tables with it. Interval overlap condition:
begin1 <= end2 AND begin2 <= end1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question