2
I need to do UPDATE with SELECT for several records, today I am with this query:
UPDATE banco.ordem SET valor = (SELECT (CEILING((litros * 3.67)*100)/100) AS valor_litros FROM banco.ordem WHERE ordens = 2763) WHERE ordens = 2763
This query updates only one record, I need to do all the records I put inside the IN ('2763','2768','2802', 'etc')
.
Has anyone ever been in a situation or has any idea how to do?
I need to select inside the update for each different record. Yes the round works too. Plus I had to use Ceiling. I can’t remember why. But I had a result that wasn’t expected.
– Willian Coqueiro
In case I use this query in a sql server to serve only one client. I marked mysql because some clients are with mysql and in the future I will implement. I know that all constructions do not work in all databases. More are similar. And just need to adapt.
– Willian Coqueiro
Willian, the internal SELECT is not necessary if what you need is only to calculate the contents of the "value" column from the "liter" column, having defined in the WHERE clause for which lines this action must be performed. Regarding the use of Ceiling(), you may have chosen it instead of round(), so that the value is always rounded up.
– José Diz
UPDATE banco.ordem 
 set valor = round((litros * 3.67), 2, 0)
 where ordens in ('2763','2768','2802', ...);
It will fetch the value of the colula and multiply and update?– Willian Coqueiro
I had to adapt, but it really worked and your answer and the most correct for the situation.
– Willian Coqueiro
Thank you. Thanks
– Willian Coqueiro