-
Notifications
You must be signed in to change notification settings - Fork 0
/
queries and subqueries.sql
75 lines (62 loc) · 2.54 KB
/
queries and subqueries.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
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use HospitalBalakovo
go
Select * --1
From Departments
ORDER by Office DESC
go
Select HeadOfDepartment as 'Заведующий', Office as 'Кабинет' --2
From Departments
ORDER by Office ASC
go
Select Surname as 'Фамилия', Name as 'Имя',Office as 'Кабинет', Specialization as 'Специализация', CostService as 'Стоимость услуг', DepartmentsId as 'Корпус' --3
From Doctors
Where Specialization = 'терапевт';
go
Select COUNT(*) as 'Количество пациентов' --4
From Patcient
Where sem_pol ='женат' or sem_pol ='замужем' and marital_status ='работает'
go
Select Name as 'Имя', Office as 'Кабинет', Specialization as 'Специализция' --5
From Doctors
Where Name like 'А%'
go
Select Surname as'Фамилии', CostService as'Стоимость услуг' --6
From Doctors
Where CostService between '2200' and '3000'
go
Select Doctors.Name AS 'Имя Доктора', --7
Doctors.Surname AS 'Фамилия Доктора',
Patcient.adress AS 'Адрес Пациента',
Reception.DayOfWeek AS 'День недели приема'
From Doctors
INNER JOIN Patcient ON Doctors.Id = Patcient.Id
INNER JOIN Reception ON Doctors.Id = Reception.Id;
go
Select Diagnosis as 'Симптомы' --8
From CardPatcient
Where Symptoms Like 'Головная боль%';
go
Select PatcientId as 'Id пациента', AVG(period) as 'Кол-вод дней лечения' --9
From Treatrment
GROUP BY PatcientId
HAVING AVG(period) > 20;
go
Select PatcientId as 'Id пациента', COUNT(*) AS "Количество лечений" --10
From Treatrment
GROUP BY PatcientId
HAVING COUNT(*) > 0;
go
Select SectionsTerritory.Districts as "Район", Doctors.Name as "Имя", Doctors.Surname as "Фамилия" --11
From SectionsTerritory
INNER JOIN Doctors ON SectionsTerritory.DoctorsId = Doctors.Id;
go
Select CP.Symptoms as "Симптомы", CP.Diagnosis as "Диагноз", CP.Medicament as "Лекарства", D.Name as "Болезнь" -- 12
From CardPatcient CP
INNER JOIN Diseases D ON CP.PatcientId = D.CardPatcientId;
go
Select Treatrment_name as 'Назначение',start_date as 'Начало лечения',end_date as 'Конец лечения',period as 'Период' -- 13
from Treatrment
INNER JOIN CardPatcient ON Treatrment.PatcientId = CardPatcient.Id
INNER JOIN Diseases ON CardPatcient.Id = Diseases.CardPatcientId
INNER JOIN SectionsTerritory ON Diseases.Id = SectionsTerritory.Id
Where SectionsTerritory.Id = '1';