我想知道是否可以使用Python和Sqlite3从传入的变量中查找列。以下是代码:
wrenches = db.execute('''
select w.id, w.desc from wrenches as w
join users as u on w.dept = u.dept and w.user = u.id
where u.id = :user
order by w.id asc''',
{'user': session['user_id']}).fetchall()
上述工作正常,但我要检查的附加条件是扳手是否共享且与用户传入的部门相同
wrenches = db.execute('''
select w.id, w.desc from wrenches as w
join users as u on w.dept = u.dept and w.user = u.id
where u.id = :user
>>> or w.shared = 1 and w.dept = :user.dept <<<
order by w.id asc''',
{'user': session['user_id']}).fetchall()
我无法理解,所以任何帮助表示赞赏。