-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy path03.sql
32 lines (25 loc) · 1.3 KB
/
03.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
-- 03. Поиск отделов, суммарная зарплата сотрудников в которых больше заданной
-- Даны две таблицы:
-- Employee (id, salary, dpt_id)
-- Department (id, name)
-- Написать sql-запрос, который выберет все названия отделов, суммарная зарплата сотрудников в которых больше 1000
create table Employee (
id int primary key,
salary int not null,
dpt_id int not null
);
create table Department (
id int primary key,
name varchar(80) not null unique
);
insert into Department(id, name) values (1, 'industrial');
insert into Department(id, name) values (2, 'finance');
insert into Department(id, name) values (3, 'sales');
insert into Employee(id, salary, dpt_id) values (1, 300, 1);
insert into Employee(id, salary, dpt_id) values (2, 600, 1);
insert into Employee(id, salary, dpt_id) values (3, 600, 2);
insert into Employee(id, salary, dpt_id) values (4, 100, 2);
insert into Employee(id, salary, dpt_id) values (5, 900, 3);
insert into Employee(id, salary, dpt_id) values (7, 400, 2);
select * from Employee;
select d.name from Department d where d.id in (select dpt_id from Employee group by dpt_id having sum(salary)>1000);