I need to run an update statement similar to the one below on MySQL. It updates values in a table based on conditions of rows in the same table. Is there a way to achieve that in QueryDSL JPA (or even that native one)?
UPDATE items,
(SELECT id, retail / wholesale AS markup, quantity FROM items)
AS discounted
SET items.retail = items.retail * 0.9
WHERE discounted.markup >= 1.3
AND discounted.quantity < 100
AND items.id = discounted.id;
You can try using derived table:
UPDATE items
SET items.retail = items.retail * 0.9
WHERE
items.id in (SELECT id FROM (select * from items) discounted WHERE discounted.quantity < 100);
I've removed few parts from your query but you get gist of the solution.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.