Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
**/__pycache__/
__pycache__/
.pytest_cache
.pytest_cache
venv/
38 changes: 19 additions & 19 deletions data/question.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ def connect_db():
port=5432,
database="postgres",
user="postgres",
password=password)
password="1234")
return conn


def question_1_query():
connection = connect_db()
cursor = connection.cursor()
cursor.execute('')
cursor.execute('SELECT *FROM students WHERE age>22;')
data = cursor.fetchall()
cursor.close()
connection.close()
Expand All @@ -27,7 +27,7 @@ def question_1_query():
def question_2_query():
connection = connect_db()
cursor = connection.cursor()
cursor.execute('')
cursor.execute('SELECT * FROM courses WHERE category='Veritabanı';')
data = cursor.fetchall()
cursor.close()
connection.close()
Expand All @@ -37,7 +37,7 @@ def question_2_query():
def question_3_query():
connection = connect_db()
cursor = connection.cursor()
cursor.execute('')
cursor.execute('SELECT * FROM students WHERE first_name LIKE 'A%';')
data = cursor.fetchall()
cursor.close()
connection.close()
Expand All @@ -47,7 +47,7 @@ def question_3_query():
def question_4_query():
connection = connect_db()
cursor = connection.cursor()
cursor.execute('')
cursor.execute('SELECT * FROM courses WHERE course_name LIKE '%SQL%';')
data = cursor.fetchall()
cursor.close()
connection.close()
Expand All @@ -57,7 +57,7 @@ def question_4_query():
def question_5_query():
connection = connect_db()
cursor = connection.cursor()
cursor.execute('')
cursor.execute('SELECT * FROM students WHERE age BETWEEN 22 AND 24 ;')
data = cursor.fetchall()
cursor.close()
connection.close()
Expand All @@ -67,7 +67,7 @@ def question_5_query():
def question_6_query():
connection = connect_db()
cursor = connection.cursor()
cursor.execute('')
cursor.execute('SELECT DISTINCT first_name, last_name ,s.student_id FROM students AS s JOIN enrollments AS e ON s.student_id=e.student_id ORDER BY s.student_id;')
data = cursor.fetchall()
cursor.close()
connection.close()
Expand All @@ -77,17 +77,16 @@ def question_6_query():
def question_7_query():
connection = connect_db()
cursor = connection.cursor()
cursor.execute('')
cursor.execute('SELECT c.course_name , COUNT (e.student_id) AS student_count FROM courses AS c JOIN enrollments AS e ON c.course_id=e.course_id WHERE category='Veritabanı' GROUP BY c.course_id ,c.course_name ORDER BY student_count;')
data = cursor.fetchall()
cursor.close()
connection.close()
return data


def question_8_query():
connection = connect_db()
cursor = connection.cursor()
cursor.execute('')
cursor.execute('SELECT c.course_name , i.name AS instructor_name FROM courses AS c JOIN course_instructors AS ci ON c.course_id=ci.course_id JOIN instructors AS i ON i.instructor_id=ci.instructor_id ORDER BY c.course_id;')
data = cursor.fetchall()
cursor.close()
connection.close()
Expand All @@ -97,7 +96,7 @@ def question_8_query():
def question_9_query():
connection = connect_db()
cursor = connection.cursor()
cursor.execute('')
cursor.execute('SELECT *FROM students AS s LEFT JOIN enrollments AS e ON s.student_id=e.student_id WHERE e.student_id IS NULL;')
data = cursor.fetchall()
cursor.close()
connection.close()
Expand All @@ -107,7 +106,7 @@ def question_9_query():
def question_10_query():
connection = connect_db()
cursor = connection.cursor()
cursor.execute('')
cursor.execute('SELECT c.course_name ,AVG(s.age) AS avg_age FROM students AS s JOIN enrollments AS e ON s.student_id=e.student_id JOIN courses AS c ON c.course_id=e.course_id GROUP BY c.course_name ORDER BY c.course_name;')
data = cursor.fetchall()
cursor.close()
connection.close()
Expand All @@ -117,7 +116,7 @@ def question_10_query():
def question_11_query():
connection = connect_db()
cursor = connection.cursor()
cursor.execute('')
cursor.execute('SELECT s.first_name, s.last_name , COUNT(c.course_name) AS total_courses FROM students AS s JOIN enrollments AS e ON s.student_id= e.student_id JOIN courses AS c ON c.course_id=e.course_id GROUP BY s.first_name,s.last_name,s.student_id ORDER BY s.student_id;')
data = cursor.fetchall()
cursor.close()
connection.close()
Expand All @@ -127,7 +126,7 @@ def question_11_query():
def question_12_query():
connection = connect_db()
cursor = connection.cursor()
cursor.execute('')
cursor.execute('SELECT i.name AS instructor_name, COUNT(i.name) AS total_courses FROM courses AS c JOIN course_instructors AS ci ON c.course_id=ci.course_id JOIN instructors AS i ON i.instructor_id=ci.instructor_id GROUP BY i.name HAVING COUNT(i.name)>1;')
data = cursor.fetchall()
cursor.close()
connection.close()
Expand All @@ -137,7 +136,7 @@ def question_12_query():
def question_13_query():
connection = connect_db()
cursor = connection.cursor()
cursor.execute('')
cursor.execute('SELECT c.course_name , COUNT(DISTINCT s.student_id) AS unique_students FROM students AS s JOIN enrollments AS e ON s.student_id=e.student_id JOIN courses AS c ON c.course_id=e.course_id GROUP BY c.course_name ORDER BY course_name;')
data = cursor.fetchall()
cursor.close()
connection.close()
Expand All @@ -147,7 +146,7 @@ def question_13_query():
def question_14_query():
connection = connect_db()
cursor = connection.cursor()
cursor.execute('')
cursor.execute('SELECT s.first_name ,s.last_name FROM students AS s JOIN enrollments AS e ON s.student_id=e.student_id JOIN courses AS c ON c.course_id=e.course_id WHERE c.course_name IN ("SQL Temelleri", "İleri SQL") GROUP BY s.first_name, s.last_name HAVING COUNT(DISTINCT c.course_name)=2;')
data = cursor.fetchall()
cursor.close()
connection.close()
Expand All @@ -157,8 +156,9 @@ def question_14_query():
def question_15_query():
connection = connect_db()
cursor = connection.cursor()
cursor.execute('')
cursor.execute('SELECT s.first_name, s.last_name, c.course_name, i.name AS instructor_name, e.enrollment_date FROM students AS s JOIN enrollments AS e ON s.student_id = e.student_id JOIN courses AS c ON c.course_id = e.course_id JOIN course_instructors AS ci ON ci.course_id = c.course_id JOIN instructors AS i ON i.instructor_id = ci.instructor_id ORDER BY e.enrollment_id;')
data = cursor.fetchall()
cursor.close()
connection.close()
return data
return data

2 changes: 1 addition & 1 deletion scripts/init_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
port=5432,
database="postgres",
user="postgres",
password="postgres"
password="1234"
)
cur = conn.cursor()

Expand Down
2 changes: 1 addition & 1 deletion tests/test_question.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def run_tests():

url = "https://kaizu-api-8cd10af40cb3.herokuapp.com/projectLog"
payload = {
"user_id": 34,
"user_id": 506,
"project_id": 35,
"user_score": user_score,
"is_auto": False
Expand Down