mysql中更新多個欄位的值怎麼做

2021-04-26 06:22:25 字數 2189 閱讀 6954

1樓:薊旎旎威溫

$total=0;

//預設變數,來用於存放累自

加結果$sql="查詢語句bai";

$sql=mysql_query($sql);

while($as=mysql_fetch_array($sql))還有一種辦法du更好,假如你要zhi累加的欄位名為price,

則:dao

$sql="select

sum(price)

astotal

from

表名where

條件";

$sql=mysql_query($sql);

$as=mysql_fetch_array($sql);

$as['total'].....

//這裡就是你想要的累加結果,直接讓

mysql

做了,php裡你就省去迴圈取值,估計效率好些。

2樓:匿名使用者

update 表名 set name=?,password=?.... where id=?

mysql 怎麼同時更新一條資料的多個欄位內容

3樓:小文

1.**執行後只更新了一條資料,因為執行第一次更新時id=1的wid更新成2,第二次更新id=2的wid時,獲取到的id=1的wid=2,更新失敗。

2.select a.wid from (select tmp.

* from change_lyt tmp) a where a.id=2看這個語句,如果此處換成select wid from change_lyt where id=2再執行上面的更新,將會報錯,you can't specify target table 『quenn』 for update in from clause.

mysql是一個關係型資料庫管理系統,由瑞典mysql ab 公司開發,目前屬於 oracle 旗下產品。mysql 是最流行的關係型資料庫管理系統之一,在 web 應用方面,mysql是最好的 rdbms (relational database management system,關聯式資料庫管理系統) 應用軟體。

mysql是一種關聯式資料庫管理系統,關聯式資料庫將資料儲存在不同的表中,而不是將所有資料放在一個大倉庫內,這樣就增加了速度並提高了靈活性。

4樓:匿名使用者

update person set address = 'zhongshan 23', city = 'nanjing'

where lastname = 'wilson'

mysql:如何更新某個欄位的值為原來的值加1?

5樓:一諾寶貝

格式:update 表名稱 set 欄位名稱 = 欄位名稱 + 1  [ where語句]

比如說資料庫中有一張student表,要想把id為1的學生成績(score)加1則

update student set score=score+1 where id = 1

mysql如何更新一個表中的某個欄位值等於另一個表的某個欄位值

6樓:海邊出來的風陽

update tb_common_verification_tk set '新欄位'='舊欄位'。

例如:a表

id  name   credits

1   aa         11

2   aa         222

3   bb        11

4   bb         222

b表id  name   credits

1   aa          222

2   bb          222

操作的是a表,能不能有什麼辦法讓b表中的credits值一直為a表中的credits最大值。

7樓:匿名使用者

update a inner join b on a.bid=b.id set a.x=b.x,a.y=b.y ;

8樓:草兒

現有表a和表b,希望更新a表,當 a.bid = b.id時,a.x = b.x, a.y=b.y:

update a inner join b on a.bid=b.id set a.x=b.x,a.y=b.y;

用mysql查詢出欄位中的前幾個字

用mysql查詢出欄位中的前幾個字可以用left 方法,如果要查一個欄位的前50個字元,sql語句舉例 select left table column,50 from table name left table column,50 表示擷取table column左邊的50個字元 擴充套件資料 s...

mysql如何查詢欄位中的資料是否包含於字串中

myid是什麼型別bai,是數值類 du型應這樣zhi寫 dao select from table where saleid 2376 and myid in 2,3,4,5,6 如果myid是字元型別,應版該這權 樣寫 select from table where saleid 2376 an...

sql根據欄位不同值查詢不同表中的欄位

select case role when 0 then select name from tablea where dd 11 else select name from tableb where dd 11 end as name from post 就是使用 case 我沒有實驗過。如果有心在...