Advertisement
Roman9234

Untitled

Mar 1st, 2024 (edited)
678
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.11 KB | None | 0 0
  1. from connection import get_connection
  2.  
  3.  
  4. @get_connection
  5. def read_students_table(cur=None):
  6.     cur.execute("SELECT * FROM STUDENTS")
  7.     students = cur.fetchall()
  8.     headers = "№\tИмя\tФамилия\tОтчество\tПол\tНомер телефона"
  9.     print(headers)
  10.     for student in students:
  11.         print(*student, sep="\t")
  12.        
  13.        
  14. @get_connection
  15. def read_teachers_table(cur=None):
  16.     cur.execute("SELECT * FROM teachers")
  17.     teachers = cur.fetchall()
  18.     headers = "№\tИмя\tФамилия\tОтчество\tПол\tНомер телефона"
  19.     print(headers)
  20.     for teacher in teachers:
  21.         print(*teacher, sep="\t")
  22.  
  23. @get_connection
  24. def read_subjects_table(cur=None):
  25.     cur.execute("SELECT subject_id, name FROM subjects")
  26.     subjects = cur.fetchall()
  27.     headers = "№\tНазвание предмета"
  28.     print(headers)
  29.     for subject in subjects:
  30.         print(*subject, sep="\t")
  31.  
  32. @get_connection
  33. def read_student_results(cur=None):
  34.     read_students_table(cur)
  35.     iden = ""
  36.     while not iden.isdigit():
  37.         iden = input("У какого студента выведем табель успеваемости? ")
  38.     iden = int(iden)
  39.     try:
  40.         cur.execute("""
  41.                    SELECT *
  42.                    FROM students
  43.                    WHERE student_id=%d
  44.                    """%(iden))
  45.     except:
  46.         print("Нет такого ученика")
  47.         return None
  48.     cur.execute("""
  49.                SELECT first_name, last_name, pater_name, name, AVG(mark)
  50.                FROM marks
  51.                INNER JOIN students ON fk_student_id = students.student_id
  52.                INNER JOIN subjects ON fk_subject_id = subjects.subject_id
  53.                WHERE fk_student_id = %d
  54.                GROUP BY first_name, last_name, pater_name, subjects.name;
  55.                
  56.                """%(iden))
  57.     headers = "Имя\tФамилия\t\tОтчество\tПредмет\t\tСредняя оценка"
  58.     table =  cur.fetchall()
  59.     print(headers)
  60.     for record in table:
  61.         print(*record, sep="\t")
  62.  
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement