From 7b11ada336555844866c7089d9a93d1549fdec72 Mon Sep 17 00:00:00 2001 From: zeynep kurt Date: Tue, 15 Sep 2026 13:38:39 +0300 Subject: [PATCH] Complete SQL project 1 --- data/questions.py | 39 ++++++++++++++++++++------------------- tests/test_question.py | 2 +- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/data/questions.py b/data/questions.py index f2c74f6..0faca55 100644 --- a/data/questions.py +++ b/data/questions.py @@ -1,22 +1,25 @@ import psycopg2 -## Bu değeri localinde çalışırken kendi passwordün yap. Ama kodu pushlarken 'postgres' olarak bırak. +## Bu değeri localinde çalışırken kendi passwordün yap. +## Ama kodu pushlarken 'postgres' olarak bırak. password = 'postgres' + def connect_db(): conn = psycopg2.connect( - host="localhost", - port=5432, - database="postgres", - user="postgres", - password=password) + host="localhost", + port=5432, + database="postgres", + user="postgres", + password=password + ) return conn def question_1_query(): connection = connect_db() cursor = connection.cursor() - cursor.execute('') + cursor.execute('SELECT customer_name, country FROM customers;') data = cursor.fetchall() cursor.close() connection.close() @@ -26,7 +29,7 @@ def question_1_query(): def question_2_query(): connection = connect_db() cursor = connection.cursor() - cursor.execute('') + cursor.execute('SELECT * FROM orders ORDER BY total_amount DESC LIMIT 5;') data = cursor.fetchall() cursor.close() connection.close() @@ -36,7 +39,7 @@ def question_2_query(): def question_3_query(): connection = connect_db() cursor = connection.cursor() - cursor.execute('') + cursor.execute('SELECT product_name, price FROM products ORDER BY price ASC LIMIT 3;') data = cursor.fetchall() cursor.close() connection.close() @@ -46,7 +49,7 @@ def question_3_query(): def question_4_query(): connection = connect_db() cursor = connection.cursor() - cursor.execute('') + cursor.execute('SELECT * FROM customers ORDER BY signup_date ASC LIMIT 10;') data = cursor.fetchall() cursor.close() connection.close() @@ -56,7 +59,7 @@ def question_4_query(): def question_5_query(): connection = connect_db() cursor = connection.cursor() - cursor.execute('') + cursor.execute('SELECT product_name, stock_quantity FROM products ORDER BY stock_quantity DESC LIMIT 1;') data = cursor.fetchall() cursor.close() connection.close() @@ -66,7 +69,7 @@ def question_5_query(): def question_6_query(): connection = connect_db() cursor = connection.cursor() - cursor.execute('') + cursor.execute('SELECT * FROM orders ORDER BY order_date DESC LIMIT 1;') data = cursor.fetchall() cursor.close() connection.close() @@ -76,7 +79,7 @@ def question_6_query(): def question_7_query(): connection = connect_db() cursor = connection.cursor() - cursor.execute('') + cursor.execute('SELECT product_name FROM products ORDER BY product_name ASC;') data = cursor.fetchall() cursor.close() connection.close() @@ -86,7 +89,7 @@ def question_7_query(): def question_8_query(): connection = connect_db() cursor = connection.cursor() - cursor.execute('') + cursor.execute('SELECT customer_id, email FROM customers ORDER BY customer_id ASC LIMIT 5;') data = cursor.fetchall() cursor.close() connection.close() @@ -96,7 +99,7 @@ def question_8_query(): def question_9_query(): connection = connect_db() cursor = connection.cursor() - cursor.execute('') + cursor.execute('SELECT order_id, total_amount FROM orders ORDER BY total_amount ASC LIMIT 3;') data = cursor.fetchall() cursor.close() connection.close() @@ -106,10 +109,8 @@ def question_9_query(): def question_10_query(): connection = connect_db() cursor = connection.cursor() - cursor.execute('') + cursor.execute("SELECT * FROM customers WHERE country = 'Turkey' ORDER BY customer_name ASC;") data = cursor.fetchall() cursor.close() connection.close() - return data - - \ No newline at end of file + return data \ No newline at end of file diff --git a/tests/test_question.py b/tests/test_question.py index 6fe01ba..bc0f23e 100644 --- a/tests/test_question.py +++ b/tests/test_question.py @@ -114,7 +114,7 @@ def run_tests(): url = "https://kaizu-api-8cd10af40cb3.herokuapp.com/projectLog" payload = { - "user_id": 34, + "user_id": 831, "project_id": 34, "user_score": user_score, "is_auto": True