Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sqlite3
- con = sqlite3.connect(':memory:')
- cur = con.cursor()
- cur.execute("create table platonic_ideal_of_a_grommet( id real, name text, color text, spindles real)")
- data = [
- (0, "economy", "red", 3),
- (1, "standard", "green", 5),
- (2, "deluxe", "blue", 7)
- ]
- cur.executemany("insert into platonic_ideal_of_a_grommet values (?, ?, ?, ?)", data)
- cur.execute("create table possibly_flawed_manifestation_of_a_grommet( id real, ideal_id real, owner text, custom_engraving text)")
- data = [
- (0, 2, "Alice", "let this grommet symbolize our bond"),
- (1, 1, "Bob", "what even IS a grommet? Buying this just to find out"),
- (2, 2, "Carol", None)
- ]
- cur.executemany("insert into possibly_flawed_manifestation_of_a_grommet values (?, ?, ?, ?)", data)
- #find all deluxe grommets with a custom engraving
- for row in cur.execute("select * from possibly_flawed_manifestation_of_a_grommet x join platonic_ideal_of_a_grommet y on x.ideal_id = y.id where x.custom_engraving is not null and y.name == 'deluxe'"):
- print(row)
- #output: (0.0, 2.0, 'Alice', 'let this grommet symbolize our bond', 2.0, 'deluxe', 'blue', 7.0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement