Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. import sqlite3
  2.  
  3. conn = sqlite3.connect('forum.sqlite')
  4. cursor = conn.cursor()
  5.  
  6. cursor.execute('''SELECT name,sql FROM sqlite_master WHERE type = "table" ''')
  7. print(cursor.fetchone())
  8. print('\n')
  9. print(cursor.fetchone())
  10. print('\n')
  11. print(cursor.fetchone())
  12. print('\n')
  13.  
  14. cursor.execute("SELECT * FROM users")
  15. print(cursor.fetchall())
  16.  
  17.  
  18.  
  19. #3.4
  20. print('\n\n\n3.4')
  21. cursor.execute("SELECT * FROM topics")
  22. print(cursor.fetchall())
  23.  
  24. #3.5
  25. print('\n\n\n3.5')
  26. cursor.execute("SELECT * FROM posts")
  27. print(cursor.fetchall())
  28.  
  29. #3.6.1
  30. print('\n\n\n3.6.1')
  31. cursor.execute("SELECT topic_name,users.name,message FROM (users JOIN posts ON posts.id_author = users.id_user) JOIN topics ON posts.id_topic = topics.id_topic")
  32. print(cursor.fetchall())
  33.  
  34. #3.6.2
  35. print('\n\n\n3.6.2')
  36. cursor.execute("SELECT name,COUNT(*) FROM users JOIN topics ON id_author = id_user GROUP BY name")
  37. print(cursor.fetchall())
  38.  
  39. #3.7
  40. print('\n\n\n3.7')
  41. cursor.execute("SELECT name,COUNT(*) FROM users JOIN posts ON id_author = id_user GROUP BY name")
  42. print(cursor.fetchall())
  43.  
  44. #3.8
  45. print('\n\n\n3.8')
  46. cursor.execute("SELECT * FROM (users JOIN posts ON posts.id_author = users.id_user) JOIN topics ON posts.id_topic = topics.id_topic")
  47. print(cursor.fetchall())
  48.  
  49. conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement