Answer the question
In order to leave comments, you need to log in
How to compose a query for multiple update mysql fields?
Hello, there is a simple table with id and float number. It is necessary to select 5 elements with the largest number, reduce it by a factor (say 100), and assign the value 1 to all other elements of the table. Is it better to organize this mass update of the table - through a loop or are there other solutions? please help me make a request.
Answer the question
In order to leave comments, you need to log in
INSERT INTO `table` (`id_lead`,`value`)VALUES (1,'test'),(3,'hello') ON DUPLICATE KEY UPDATE value=VALUES(value)
begin;
create temporary table max5float select id as maxid from `table` order by float desc limit 5; -- проверьте что тут будет, я постоянно путаю направления сортировки
update `table` left join max5float on id=maxid set `float`=if(maxfloat is null, 1, `float`*100);
drop temporary table max5float;
commit;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question