-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththird.sql
More file actions
97 lines (82 loc) · 2.48 KB
/
Copy paththird.sql
File metadata and controls
97 lines (82 loc) · 2.48 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
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
create database OkulYonetimi
use OkulYonetimi;
create table Students(
StudentID int primary key identity(1,1),
FirstName varchar(50) not null,
LastName varchar(50) not null,
Email varchar(100) not null,
EnrollmentDate datetime default GETDATE()
);
create table Courses(
CourseID int primary key identity(1,1),
CourseName varchar(100) not null,
Credits int not null
);
create table Grades(
GradeID int identity(1,1) primary key,
StudentID int not null,
CourseID int not null,
Grade decimal(5,2),
GradeDate datetime default GETDATE(),
foreign key (StudentID) references Students(StudentID),
foreign key (CourseID) references Courses(CourseID)
);
--DML
insert into Students(FirstName,LastName,Email)
values
('Ahmet', 'Yýlmaz', 'ahmet.yilmaz@email.com'),
('Zeynep', 'Kara', 'zeynep.kara@email.com'),
('Murat', 'Demir', 'murat.demir@email.com');
insert into Grades(StudentID,CourseID,Grade)
values
(1, 1, 85),
(1, 2, 90),
(2, 1, 75),
(2, 3, 80),
(3, 2, 88);
select * from Courses;
insert into Courses(CourseName, Credits)
values
('Matematik', 3),
('Fizik', 4),
('Kimya', 3);
insert into Grades(StudentID, CourseID, Grade)
values
(1, 1, 85),
(1, 2, 90),
(2, 1, 75),
(2, 3, 80),
(3, 2, 88);
--Information about Students and Their Courses
select S.FirstName, S.LastName , C.CourseName, G.Grade
from Students S
inner join Grades G on S.StudentID = G.StudentID
inner join Courses C on G.CourseID = C.CourseID;
--Average Grade of Each Student
select S.FirstName , S.LastName, avg(G.Grade) as AverageGrade
from Students S
inner join Grades G on S.StudentID = G.StudentID
group by S.FirstName , S.LastName;
--Students Scoring 80 and Above
select S.FirstName , S.LastName ,C.CourseName , G.Grade
from Students S
inner join Grades G on S.StudentID = G.StudentID
inner join Courses C on G.CourseID = C.CourseID
where G.Grade >=80;
--Students Taking Only One Course
select S.FirstName, S.LastName
from Students S
inner join Grades G on S.StudentID = G.StudentID
group by S.StudentID
having count(G.CourseID) =1;
--Students with the Highest Scores
select S.FirstName,S.LastName,C.CourseName,G.Grade
from Students S
inner join Grades G on S.StudentID = G.StudentID
inner join Courses C on G.CourseID = C.CourseID
where G.Grade = (select max(Grade) from Grades);
--Number of Students with Courses
select C.CourseName,count(G.StudentID) as StudentCount
from Courses C
left join Grades G on C.CourseID = G.CourseID
group by C.CourseName;