Select with a condition

EasySQLite Programs · 4 of 20

Write a Python program to select students who scored above 80.

Advertisement
Output
Asha 91
Meena 88

Approach

  1. WHERE marks > ?.

Solution

Python
import sqlite3 conn = sqlite3.connect(":memory:")conn.execute("CREATE TABLE students (name TEXT, marks INTEGER)")conn.executemany("INSERT INTO students VALUES (?, ?)", [("Asha", 91), ("Ravi", 74), ("Meena", 88)])for name, marks in conn.execute("SELECT name, marks FROM students WHERE marks > ? ORDER BY marks DESC", (80,)):    print(name, marks)
Output
Asha 91
Meena 88

Learn the concept

New to this topic? Read the lesson, then come back.

More sqlite programs

← All 20 SQLite Programs

Leave a Comment