-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3.sql
103 lines (85 loc) · 3.06 KB
/
3.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
-- име на трен и спорт
-- име на студ и спорт
-- име на спорт и място
-- име на спорт и място, но и тези за които няма място
-- име на спорт и място, но и залите в които няма спорт
-- име на спорт и място, но и гопрните 2
use school_sport_clubs;
select coaches.name as Coach, sports.name as Sport
from coaches
join sports
on coaches.id in
( select coach_id from sportGroups
where sportGroups.sport_id=sports.id);
select students.name as Student, sports.name as Sport
from students
join sports
on students.id in
( select student_id from student_sport
where student_sport.sportGroup_id
in
(select id from sportGroups
where sportGroups.sport_id=sports.id ));
select sports.name as Sport, sportGroups.location as Place
from sports
join sportGroups
on sports.id=sportGroups.sport_id;
select sports.name as Sport, sportGroups.location as Place
from sports
left join sportGroups
on sports.id=sportGroups.sport_id;
select sports.name as Sport, sportGroups.location as Place
from sports
right join sportGroups
on sports.id=sportGroups.sport_id;
select sports.name as Sport, sportGroups.location as Place
from sports
left join sportGroups
on sports.id=sportGroups.sport_id
union
select sports.name as Sport, sportGroups.location as Place
from sports
right join sportGroups
on sports.id=sportGroups.sport_id;
-- име и тел на всички студ трен волейб
select students.name as Student, students.phone as Phone
from students
where students.id in
(select student_id from student_sport
where sportGroup_id in
(select id from sportGroups
where sport_id in
(select id from sports
where sports.name='Volleyball')
)
);
-- име на студ, които трен в понед, като резулт са подред по име на ст
select students.name as Student
from Students
where students.id in
(select student_id from student_sport
where sportGroup_id in
(select id from sportGroups
where dayOfWeek='Monday')
);
-- име на учен, клас, ид на групата в която трен, но само за учен в неделя при труньо Иван Тодоров Петков
select students.name as Student, students.class as Class, sportGroups.id as GroupNo
from students
join sportGroups
on students.id in
(select student_id from student_sport
where sportGroup_id in
(select id from sportGroups
where dayOfWeek='Sunday' and coach_id in
(select id from coaches
where name='Ivan Todorov Petkov'
)
)
);
-- име на учен и общата сума, която е платил по години, като резултатите са подредени по име на учен
select students.name as Student, sum(taxespayments.paymentAmount) as PaidTax, taxespayments.year as forYear
from students
join taxespayments
on students.id=taxespayments.student_id
group by Student,forYear
order by Student;