import sqlite3
my_conn = sqlite3.connect('my_db.db')
print("Connected to database successfully")
q="SELECT COUNT(DISTINCT(class)) FROM student"
try:
my_cursor=my_conn.execute(q)
for row in my_cursor:
print(row[0])
except sqlite3.Error as my_error:
print("error: ",my_error)
q="SELECT DISTINCT class,sex FROM student"
try:
my_cursor=my_conn.execute(q)
for row in my_cursor:
print(row[0],row[1])
except sqlite3.Error as my_error:
print("error: ",my_error)
q="SELECT DISTINCT class FROM student WHERE class NOT NULL"
try:
my_cursor=my_conn.execute(q)
for row in my_cursor:
print(row[0])
except sqlite3.Error as my_error:
print("error: ",my_error)