-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHomework1
More file actions
57 lines (44 loc) · 1.72 KB
/
Homework1
File metadata and controls
57 lines (44 loc) · 1.72 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
drop table departament;
drop table employee;
create table departament (id serial primary key,
name varchar(100),
isProfit boolean);
insert into departament (name, isProfit)
values ('accounting', false);
insert into departament (name, isProfit)
values ('credit', true);
insert into departament (name, isProfit)
values ('sales', true);
insert into departament (name, isProfit)
values ('management', true);
select * from departament;
create table employee (id serial primary key,
full_name varchar(100),
salary int,
departament_id int,
constraint deptId foreign key (departament_id) references departament(id));
insert into employee(full_name, salary, departament_id)
values ('Petrov Ivan', 30000, 3);
insert into employee(full_name, salary, departament_id)
values ('Ivaniva Natalya', 50000, 1);
insert into employee(full_name, salary, departament_id)
values ('Mirskih Petr', 100000, 4);
insert into employee(full_name, salary, departament_id)
values ('Ulyukaev Vladimir', 200000, 4);
insert into employee(full_name, salary, departament_id)
values ('Zamorskiy Viktor', 70000, 2);
select * from employee where departament_id = 4;
select sum (salary) as salary_amount from employee;
select e.full_name, d.isProfit
from employee e inner join departament d on e.departament_id = d.id;
select * from employee
where salary between 10000 and 100000
delete from employee where id = 3;
update departament set name = 'Deposite', isProfit = false
select * from employee
where lower(full_name) ILIKE '%van%';
select d.name, avg(salary)::numeric(10,2) as average_salary
from employee e inner join departament d on e.departament_id = d.id
group by d.name
drop table departament;
drop table employee;