SQL語句中有更新同欄位下,不同行給予不同值的嗎?(用一

2021-04-26 06:21:20 字數 2851 閱讀 6610

1樓:sql的藝術

update

set欄位名zhi=case when 欄位名x='a' then 1  when 欄位名x='b' then 2 else 3 end

from

表名where

條件dao1

and 條件2

....

使用case語句,即可做版到你得要權求

sql語句更新資料庫中一個表中同一欄位(根據其他欄位)賦予不同值

2樓:匿名使用者

update jiage set price=case when uid>0 and uid<=5 then '$a' when uid>5 and uid<=10 then '$b' when uid>10 and uid<=20 then '$c' end

貌似你那語句有地方寫錯了,怎麼又大於10又小於等於10的

如何在sql語句中給同一個欄位每行賦不同的值

3樓:匿名使用者

1、使用標識列的方式來做(列型別為:數值型)

2、使用列型別為:[uniqueidentifier],預設值為newid()

同一欄位根據不同條件更新的sql語句怎麼寫

4樓:匿名使用者

沒太明白你的需求

比如,版

這樣?權

update ta set col1 = (select case tb.a > 1000 then 1 else 0 end from tb where ta.id = tb.

aid)

where ...

5樓:情又獨中

update tablename set col=decode(.....)

一條sql update如何同時更新兩個欄位的值按不同條件

6樓:匿名使用者

能,但是你說的不清楚,寫個語句你看看,能否受到啟示。

update 表名 set 欄位1= case when 條件版1 then 1 else 0 end, 欄位2= case when 條件2 then 0 else 1 end

意思你理解了,權就會寫了,這裡的值我用1和0代替的,具體的看你的是啥了。

用case when 你去研究研究這個語法。呵呵。

用一條sql語句同時更新一個表中的兩個欄位

7樓:匿名使用者

update 表名 set 欄位1=-5 ,欄位2=100 where 欄位3='0101'

前面的and 換成逗號,最後那個0101要用單引號引起來(前面幾位都沒有發現啊)。

8樓:匿名使用者

資料型別是 int 是 不需要 引號的

你要把報錯發上來,你發個語句看不出來的。

9樓:

update 表名 set 欄位1=-5,欄位2=100 where 欄位3=0101;

使用sql語句如何查詢一個表中一個欄位的值相同,另外一個欄位的值不同?急! 200

10樓:匿名使用者

給點示例資料,然後給個結果資料,才知道你的具體要求。你的描述有歧義的。

11樓:手機使用者

假設表名為table,相同欄位為c,不同欄位為d

select * from table as a ,table as b where a.c=b.c and a.d<>b.d

12樓:凌風雲傲天下

select 列名1,列名2 from 表名1

group by 列名1,列名2 order by 列名1

分組排序查詢。

13樓:燕雪鳳舞

select distinct

a.欄位

1,a.欄位2,

from

table a

join table b on a.欄位2 != b.欄位2where

a.欄位1= b.欄位1

order by

a.欄位1,

a.欄位2

sql語句,如何對同一列資料中不同的值,計數

14樓:匿名使用者

|select bg_severity,count(*) as row_count

from 表名

du group by bg_severity

結果:zhi

daobg_severity row_count

1-低專 xx

2-中 xx

1-高 xx

select sum(case when bg_severity = n'1-低' then 1 else 0 end) as [1-低],

sum(case when bg_severity = n'2-中' then 1 else 0 end) as [2-中],

sum(case when bg_severity = n'3-高' then 1 else 0 end) as [3-高]

from 表名

結果:1-低 |屬2-中 |3-高

xx |xx | xx

15樓:匿名使用者

select bg_severity,count(*) from 表名 group by bg_severity

sql更新語句若某欄位為空則更新此欄位否則不更新

mysql的寫法,其他資料庫同理,只有當前時間的引數不同 update test set endtime now where endtime is null update test set stoptime getdate where select count from testwhere id s...

acces中的sql語句中as為欄位起別名時欄位間有空格用單

雙引號,沒有特殊字元 如空格等 可以不加 select 姓名 as 姓 名 from infor sql資料庫 as後面的別名需要加雙引號嗎?和不加有什麼區別?求解 不用加引號。如果別名是保留字或者別名中含有會引起歧義的特殊字元 如空格 時,就要用方括號 不是引號 括起來。不用加的,除非你as後面的...

SQL語句中as的作用sql語句中as的作用?

有點像重新命名的意思 比如select count as num from table 這句話的意思是,table表裡面有多少條記錄,並把這個記錄的個數賦值給一個臨時變數num 到時候就可以從num中獲得記錄個數 如果不用as,是不是很難獲取記錄個數 同理,像樓上各位仁兄說的,起別名,可以這麼理解我...