I want to update the entire data, but I have to calculate the margin rate at the purchase price and divide it by the exchange rate, but there is a data format errorㅠ;;
SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect decimal value: 'buy_amt * 0.00097812555575316' for column 'prod' at row 1 (SQL: update prod set value = 10, price = buy_amt * 0.00097812555575316 )
What's wrong with turning the sql in the error code to run properly
use DB;
DB::update("update prod set value = ?, price = ?, ",
[
$datas["value"],
"buy_amt * ".(1+($datas["value"]/100))/$datas["price"],
]);
So you want mysql to do the math himself? You should use DB::raw()
If you refer to this case, you can roughly do this.
DB::table('prod')->update([
'value' => $datas["value"],
'price' => DB::raw("buy_amt * ".(1+($datas["value"]/100))/$datas["price"])
]);
PS: Personally, I don't recommend having mysql compute. It would be faster and smoother (whether PHP or mysql) to get the calculations needed from the source before sending the update.
© 2024 OneMinuteCode. All rights reserved.