From 267a65039f840d0f8d340fad919c86208c0dbced Mon Sep 17 00:00:00 2001 From: jay817 Date: Sat, 21 Sep 2024 22:05:26 -0400 Subject: [PATCH] Update sqlite3-python/README.md --- sqlite3-python/README.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/sqlite3-python/README.md b/sqlite3-python/README.md index 4f73506..c9facc3 100644 --- a/sqlite3-python/README.md +++ b/sqlite3-python/README.md @@ -20,14 +20,14 @@ class SQL: ``` ```python -# +#%% try: get_ipython() except: display = print sql = SQL() sql -# +#%% # 학생 테이블 생성 sql('''CREATE TABLE IF NOT EXISTS students (id INTEGER PRIMARY KEY, name TEXT, age INTEGER, grade INTEGER)''') @@ -43,7 +43,7 @@ sql('''CREATE TABLE IF NOT EXISTS enrollments FOREIGN KEY(course_id) REFERENCES courses(id))''') sql -# +#%% # 학생 데이터 삽입 sql('INSERT INTO students (name, age, grade) VALUES (?, ?, ?)', ('김철수', 20, 2)) sql('INSERT INTO students (name, age, grade) VALUES (?, ?, ?)', ('이영희', 22, 4)) @@ -67,7 +67,7 @@ display(sql.courses) print("\nEnrollments:") display(sql.enrollments) -# +#%% # JOIN을 사용하여 학생별 수강 과목 조회 print("\n학생별 수강 과목:") enrollments_df = sql(''' @@ -78,7 +78,7 @@ enrollments_df = sql(''' ''') display(enrollments_df) -# +#%% # 특정 과목을 수강하는 학생 수 조회 course_name = '알고리즘' result = sql(''' @@ -89,7 +89,7 @@ result = sql(''' ''', (course_name,)) print(f"\n'{course_name}' 과목을 수강하는 학생 수: {result['student_count'].iloc[0]}") -# +#%% # 가장 많은 학생이 수강하는 과목 조회 most_popular_course = sql(''' SELECT courses.name, COUNT(*) as enrollment_count @@ -101,7 +101,7 @@ most_popular_course = sql(''' ''') print(f"\n가장 인기 있는 과목: {most_popular_course['name'].iloc[0]} (수강생 {most_popular_course['enrollment_count'].iloc[0]}명)") -# +#%% # 최종 상태 출력 print("\n최종 상태:") print("Students:") @@ -110,4 +110,5 @@ print("\nCourses:") display(sql('SELECT * FROM courses')) print("\nEnrollments:") display(sql('SELECT * FROM enrollments')) + ``` \ No newline at end of file