我有这个查询:
user = self.db.query("SELECT DISTINCT u.id, u.name, n.network_id, n.perm \
FROM users as u LEFT OUTER JOIN nets_permissions as n \
ON u.id = n.user_id WHERE u.id!=%s", int(usr_id))
列“perm”(权限)是一个 int 值,可以是 1、2、3、ecc 之类的值。或空值。我想要这样的查询:
user = self.db.query("SELECT DISTINCT u.id, u.name, n.network_id, n.perm \
FROM users as u LEFT OUTER JOIN nets_permissions as n \
ON u.id = n.user_id WHERE u.id!=%s" AND n.perm!=3, int(usr_id))
所以,我想从查询中删除 perm=3 的记录。
我认为我可以通过这种方式检索具有 perm=3 的用户的 id:
self.lock_tables("read", ['nets_permissions'])
admin = self.db.query("SELECT user_id FROM nets_permissions \
WHERE network_id=%s AND perm=3", nid)
self.unlock_tables()
然后我可以写
self.lock_tables("read", ['users as u', 'nets_permissions as n'])
user = self.db.query("SELECT DISTINCT u.id, u.name, n.network_id, n.perm \
FROM users as u LEFT OUTER JOIN nets_permissions as n \
ON u.id = n.user_id WHERE u.id!=%s AND u.id!=%s", int(usr_id), int(admin))
self.unlock_tables()
但这不起作用....
任何的想法?
谢谢