英文:
Apply the same SQL query to all partners [Odoo]
问题
我想对每个合作伙伴都添加一个税收,如果可能的话,只需一个查询。我有4700个合作伙伴,所以逐个查询是不可行的。我正在寻找一个像循环函数一样执行此操作的查询。
这是我已经有的查询。在这种情况下,仅适用于ID为9915的合作伙伴(并且可以正常工作)。
INSERT INTO
res_partner_perception
(id, perception_id, create_date, percent, excluded, partner_id)
VALUES
((SELECT COALESCE(MAX(id), 0) FROM res_partner_perception) + 1,114,
now(),3,0,9915);
但我想将此查询应用于数据库中存在的所有partner_ids。我该如何做到这一点?
英文:
I want to add a tax to every single partner with a single query if it's possible. I have 4700 partners, so it's non-viable to do it query by query. I'm looking for a query that do this like if it's a loop function.
This is the Query that I already have. In this case only apply for partner with ID 9915 (And works OK).
INSERT INTO
res_partner_perception
(id, perception_id, create_date, percent, excluded, partner_id)
VALUES
((SELECT COALESCE(MAX(id), 0) FROM res_partner_perception) + 1,114,
now(),3,0,9915);
But i want to apply this query to ALL partner_ids that exists in the database. How can i do this?
答案1
得分: 0
INSERT INTO res_partner_perception
(id, perception_id, create_date, percent, excluded, partner_id)
SELECT
(SELECT COALESCE(MAX(id), 0) FROM res_partner_perception) + row_number() over(),
114,
now(),
3,
0,
p.id
FROM all_partner_ids p;
英文:
Assuming that there is a table all_partner_ids
in your database you could do a query like this:
INSERT INTO res_partner_perception
(id, perception_id, create_date, percent, excluded, partner_id)
SELECT
(SELECT COALESCE(MAX(id), 0) FROM res_partner_perception) + row_number() over(),
114,
now(),
3,
0,
p.id
FROM all_partner_ids p;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论