简体   繁体   English

SQL语句更新列

[英]SQL statement to update columns

How I can add a column in a sql parameter on laravel 5.3? 如何在laravel 5.3的sql参数中添加列?

I have a table with: id,name,zipcode,nearag1 and a variable named agent 我有一个表,其中包含: id,name,zipcode,nearag1和一个名为agent的变量

I want a SQL statement for laravel 5.3 like this: 我想要这样的laravel 5.3的SQL语句:

*UPDATE items set near_ag1=ABS(zipcode-$agent)* traslate to laravel 5.3 

I made a SQL raw statement like this: 我做了这样的SQL原始语句:

$Agzc1= $request2->input('Agzc1');

Item::raw("UPDATE items set near_ag1=ABS(zipcode-?)",[$Agzc1]); 

This SQL produces no errors but the column near_ag1 is saving 0 values. 此SQL不会产生任何错误,但是near_ag1列正在保存0个值。

有一种用于绑定的方法,您不应该完全生硬,因此:

Item::update(['near_ag1' => DB::raw('ABS(zipcode-?)'))->setBindings([$Agzc1]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM