是否可以从波兰(country_id = 76)返回城市列表(例如),但是在WHERE中没有直接使用国家名称(country.country行的值)country_id?数据库的结构如下。
@app.route('/citiess')
def city_list3():
db = get_db()
data = db.execute('''
SELECT city FROM city
JOIN country ON city.country_id = country.country_id
WHERE city.country_id = 76
''').fetchall()
data_json = []
for i in data:
data_json.extend(list(i))
return jsonify(data_json)
答案 0 :(得分:1)
为什么不在加入的WHERE
表上执行country
条款,即:
data = db.execute("""SELECT city FROM city
JOIN country USING (country_id)
WHERE country.country = ?""", ("Poland", )).fetchall()
答案 1 :(得分:0)
我看到它也有效:
data = db.execute('''
SELECT city FROM city
JOIN country ON country.country_id = city.country_id
WHERE country.country = "Poland"
''').fetchall()
无论如何,谢谢