Repository navigation
Expand file tree
/
Copy path4.sql
More file actions
275 lines (230 loc) · 7.84 KB
/
Copy path4.sql
File metadata and controls
275 lines (230 loc) · 7.84 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
CREATE DATABASE ThesisRepo;
USE ThesisRepo;
CREATE TABLE Student(
name varchar(50),
rollNo varchar(10),
age int,
department varchar(20),
mobileNo bigint,
emailId varchar(50),
PRIMARY KEY(rollNo)
);
CREATE TABLE Guide(
GuideId int,
guide_name varchar(50),
researchArea varchar(50),
designation varchar(50),
dept varchar(20),
guide_mobileNo bigint,
guide_emailId varchar(30),
PRIMARY KEY(GuideId)
);
CREATE TABLE Thesis(
Id int,
title varchar(50),
central_area varchar(50),
PRIMARY KEY(Id)
);
CREATE TABLE Submission(
student_rollNo varchar(10),
guide_id int,
thesisId int,
sub_date DATE,
FOREIGN KEY (student_rollNo) REFERENCES Student(rollNo),
FOREIGN KEY (guide_id) REFERENCES Guide(GuideId),
FOREIGN KEY (thesisId) REFERENCES Thesis(Id),
PRIMARY KEY (student_rollNo, guide_id, thesisId)
);
CREATE TABLE IndexTable(
t_Id int,
keyword varchar(50),
FOREIGN KEY (t_Id) REFERENCES Thesis(Id),
PRIMARY KEY(t_Id)
);
INSERT INTO Student VALUES
('Ajay', 'CS24P05', 22, 'CS', 9536214568, 'ajay@gmail.com'),
('Sanjay', 'AI24P10', 25, 'AI', 9523914568, 'sanjay@gmail.com'),
('Indraj', 'EC25MS23', 27, 'EC', 9623147895, 'indraj@gmail.com'),
('Ashiq', 'ME23P18', 23, 'ME', 6122785314, 'ashiq@gmail.com'),
('Manu', 'CE22MS02', 22, 'CE', 8185862342, 'manu@gmail.com'),
('Ameer', 'CS23MS01', 23, 'CS', 9285647123, 'ameer@gmail.com'),
('Dileep', 'AI23P15', 24, 'AI', 9112346789, 'dileep@gmail.com');
INSERT INTO Guide VALUES
(51523, 'Abhinav', 'Machine Learning', 'prof', 'CSE', 9592934568, 'abhinav@gmail.com'),
(62841, 'Anirudh', 'Cyber Security', 'prof', 'CSE', 9275543214, 'anirudh@gmail.com'),
(45623, 'Ameliya', 'Building Architecture', 'prof', 'CE', 9592934568, 'ameliya@gmail.com'),
(18785, 'Jacob', 'Semiconductor Theory', 'prof', 'ECE', 9592934568, 'jacob@gmail.com'),
(23761, 'Niranjan', 'Artificial Intelligence', 'Assist prof', 'CSE', 6257894130, 'niranjan@gmail.com'),
(32451, 'Pravin', 'Software Engineering', 'Assist prof', 'IT', 9876543210, 'pravin@gmail.com'),
(42134, 'Diana', 'Algorithms', 'prof', 'CSE', 9002345671, 'diana@gmail.com');
INSERT INTO Thesis VALUES
(1254, 'Is AI Essential', 'AI'),
(2244, 'Security Matters', 'Cyber Security'),
(2245, 'Privacy Matters', 'Cyber Security'),
(1571, 'Intelligent Machine', 'AI'),
(3004, 'Construction Theory', 'Architecture of Building'),
(1113, 'Algorithm Analysis and Development', 'Computer Algorithms'),
(2111, 'Neural Networks', 'AI'),
(3322, 'Digital Architecture', 'Architecture of Building'),
(4105, 'Advanced Cyber Security', 'Cyber Security'),
(5123, 'AI in Healthcare', 'Artificial Intelligence');
INSERT INTO Submission VALUES
('CS24P05', 51523, 1254, '2024-05-07'),
('CE22MS02', 45623, 1571, '2024-05-07'),
('AI24P10', 45623, 2244, '2024-05-07'),
('AI24P10', 18785, 2245, '2024-06-12'),
('CS23MS01', 42134, 1113, '2024-07-19'),
('CS23MS01', 42134, 1571, '2024-07-19'),
('AI23P15', 23761, 2111, '2024-08-25'),
('ME23P18', 32451, 3322, '2024-09-15'),
('CS24P05', 51523, 4105, '2024-09-20'),
('AI23P15', 23761, 5123, '2024-09-25'),
('AI23P15', 23761, 3004, '2024-09-25'),
('AI23P15', 23761, 1571, '2024-09-25');
INSERT INTO IndexTable VALUES
(1254, 'AI, Future Technology'),
(2244, 'Approximation Algorithms, Hashing Algorithms'),
(3004, 'Construction'),
(1571, 'AI, Deep Learning, Neural Networks'),
(1113, 'Algorithms'),
(2111, 'Neural Networks'),
(3322, 'Architecture');
SELECT * FROM Student;
SELECT * FROM Guide;
SELECT * FROM Thesis;
SELECT * FROM Submission;
SELECT * FROM IndexTable;
-- --
CREATE VIEW Thesis_Details AS
SELECT *
FROM Submission AS s JOIN Thesis AS t ON s.thesisId = t.Id
JOIN Student AS st ON s.student_rollNo = st.rollNo
JOIN Guide AS g ON s.guide_id = g.GuideId;
SELECT * FROM Thesis_Details;
-- --
CREATE VIEW Thesis_keyword AS
SELECT *
FROM Submission JOIN (
SELECT t_Id, SUBSTRING_INDEX(keyword,',',1) AS keyword
FROM IndexTable
UNION
SELECT t_Id, SUBSTRING_INDEX(SUBSTRING_INDEX(keyword,',',2),', ',-1) AS keyword
FROM IndexTable
UNION
SELECT t_Id, SUBSTRING_INDEX(keyword,', ',-1) AS keyword
FROM IndexTable) AS subq
ON subq.t_Id=Submission.thesisId
ORDER BY Submission.thesisId;
SELECT * FROM Thesis_keyword;
-- (a)
SELECT DISTINCT g.*
FROM Thesis_keyword AS tk JOIN Guide AS g
ON tk.guide_id = g.GuideId
WHERE tk.keyword = 'Approximation Algorithms';
-- (b)
SELECT *, 'Max_Thesis' AS status
FROM Guide
WHERE GuideId IN (
SELECT guide_id
FROM Submission
GROUP BY guide_id
HAVING COUNT(*) = (
SELECT MAX(thesisNo)
FROM (
SELECT COUNT(*) AS thesisNo
FROM Submission
GROUP BY guide_id
) AS subq
)
);
SELECT *, 'Min_Thesis' AS status
FROM Guide
WHERE GuideId IN (
SELECT guide_id
FROM Submission
GROUP BY guide_id
HAVING COUNT(*) = (
SELECT MIN(thesisNo)
FROM (
SELECT COUNT(*) AS thesisNo
FROM Submission
GROUP BY guide_id
) AS subq
)
);
-- (c)
SELECT name, rollNo, age, department, mobileNo, emailId, central_area, title
FROM Thesis_Details
WHERE rollNo IN (
SELECT student_rollNo
FROM Thesis_Details
GROUP BY student_rollNo, central_area
HAVING COUNT(DISTINCT guide_id) >= 2
);
-- (d)
SELECT *
FROM Guide
WHERE GuideId IN (
SELECT guide_id
FROM Thesis_Details
WHERE SUBSTRING(rollNo, 5,1) = 'P'
GROUP BY guide_id
HAVING COUNT(DISTINCT central_area)>1
);
-- (e)
SELECT keyword, COUNT(CASE WHEN SUBSTRING(student_rollNo, 5, 1) = 'P' THEN 1 END) AS 'PhD Count', COUNT(CASE WHEN SUBSTRING(student_rollNo,5,2) = 'MS' THEN 1 END) AS 'MS Count'
FROM Thesis_keyword
GROUP BY keyword;
-- (f)
SELECT *
FROM Guide
WHERE GuideId NOT IN (
SELECT guide_id
FROM Submission
WHERE sub_date BETWEEN '2024-05-07' AND '2024-06-07'
);
-- (g)(1)
SELECT central_area, COUNT(*) AS Count, 'Most trending area' AS category
FROM Thesis_Details AS t
GROUP BY t.central_area
HAVING COUNT(*) = (
SELECT MAX(max_count)
FROM (
SELECT COUNT(*) AS max_count
FROM Thesis_Details AS t
GROUP BY t.central_area
) AS subq
);
-- (g)(2)
SELECT central_area, COUNT(*) AS Count, 'Least trending area' AS category
FROM Thesis_Details AS t
GROUP BY t.central_area
HAVING COUNT(*) = (
SELECT MIN(min_count)
FROM (
SELECT COUNT(*) AS min_count
FROM Thesis_Details AS t
GROUP BY t.central_area
) AS subq
);
-- (h)
SELECT *
FROM Guide
WHERE GuideId IN (
SELECT DISTINCT guide_id
FROM Thesis_Details
WHERE SUBSTRING(rollNo, 5,2) = 'MS'
GROUP BY guide_id
HAVING COUNT(DISTINCT central_area) = 1
);
-- (i)
SELECT *
FROM Student
WHERE rollNo IN (
SELECT student_rollNo
FROM Thesis_keyword AS tk
GROUP BY student_rollNo
HAVING COUNT(DISTINCT thesisId) > 1 AND COUNT(keyword) = COUNT(DISTINCT keyword)
);
-- Here (DISTINCT Thesis id) is taken because thesis id is repeated in the view if it contains more than 1 keyword, but not taken in 2nd conditon of HAVING clause as no 2 keyword should be repeated
DROP DATABASE ThesisRepo;