-2

Can you tell me how to filter the Customers table by State and City? Thank you

@app.route('/get-customers', methods=['GET', 'POST'])
def get_customers():
    query = 'SELECT FirstName, LastName  FROM customers WHERE City = "Oslo"  or City = "Paris"'
    records = execute_query(query)
    result = '<br>'.join([str(record) for record in records])
    return result


def execute_query(query):
    db_path = os.path.join(os.getcwd(), 'chinook.db')
    conn = sqlite3.connect(db_path)
    cur = conn.cursor()
    cur.execute(query)
    record = cur.fetchall()
    return record
DeF-F
  • 13
  • 1

1 Answers1

0

At the moment I couldn't see variables for the city and the state. Probably you could add them to your endpoint.

For filtering you could do something like this:

state = "State" 
city = "City" 
c.execute('SELECT FirstName, LastName  FROM customers WHERE City=?  and State=? ', state, city)