[英]Peewee: how to select multiple rows where id matches the list?
list_of_ids = "23,55,11,24"
job = Job.select().join(User).where(Job.id IN (list_of_ids))
我想獲取屬於特定用戶的所有作業,其中作業ID與提供list of ids
匹配。 但是,我一直收到語法錯誤,並且在Peewee網站上找不到任何文檔。
我希望能夠對提供的ID列表進行更新和刪除操作。
如果Peewee可以讓我插入一個SQL字符串,那就太好了。 我會做
SELECT job.name FROM user INNER JOIN job ON user.id = job.id
WHERE job.id IN (23,55,11,24)
您想要類似的東西:
Job.select().join(User).where(Job.id << list_of_ids.split(','))
x << y
將執行x IN y,其中y是列表或查詢 ,如此處所述: https : //peewee.readthedocs.io/en/latest/peewee/query_operators.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.