Mysql中查詢表,把結果中的NULL替換成0,請寫出s

2021-10-16 10:59:50 字數 5978 閱讀 5183

1樓:匿名使用者

可以用case when解決

select case when 欄位 is null then 0 else 欄位 end from 表名

2樓:好像是夢

1、mssql: isnull()

語法isnull ( check_expression , replacement_value )

引數check_expression

將被檢查是否為 null的表示式。check_expression 可以是任何型別的。

replacement_value

在 check_expression 為 null時將返回的表示式。replacement_value 必須與 check_expresssion 具有相同的型別。

返回型別

返回與 check_expression 相同的型別。

註釋如果 check_expression 不為 null,那麼返回該表示式的值;否則返回 replacement_value。

2、oracle: nvl()

語法nvl(eexpression1, eexpression2)

引數eexpression1, eexpression2

如果 eexpression1 的計算結果為 null 值,則 nvl() 返回 eexpression2。如果 eexpression1 的計算結果不是 null 值,則返回 eexpression1。eexpression1 和 eexpression2 可以是任意一種資料型別。

如果 eexpression1 與 eexpression2 的結果皆為 null 值,則 nvl( ) 返回 null

3樓:秦江波

select ifnull(colname,0) from tablename

sql語句中 查詢結果 把0 替換為 空,怎麼弄?

4樓:匿名使用者

如果兩個指定的表示式相等,則返回空值 nullif查詢結果 把0 替換為 空, 也就是 nullif ( 查詢結果列, 0 )

例如:sql> select

2 nullif(0,0) as "0",3 nullif(1,0) as "1",4 nullif(2,0) as "2",5 nullif(3,0) as "3"

6 from

7 dual;

0 1 2 3---------- ---------- ---------- ----------

1 2 3sql>

5樓:匿名使用者

參考replace 語法,或者update 更新

6樓:匿名使用者

select replace(column,0,'null') from [table]

sql如何把查詢到的null替換成空值?

7樓:妞兒媽媽

1、這要看你如何儲存你查詢的結果。只能是你把你查詢的結果儲存為0,查詢不會改變原本存在的值。表名test,欄位a=.

null.(int型),欄位b=1,欄位c=2 :select * from test into tabel test1

update set a=0 where a=.null。

2、用 isnull(欄位名, '')  可以將null的欄位轉換為空值,這在多個欄位連線時很有用,因為null值+任何欄位都是null。

3、將null替換為空create procedure fill_null@tablename varchar(100) --表名asdeclare @colname varchar(100)declare col_cur cursor for select c.name from syscolumns c,sysobjects o where c.id=o.

id and o.name=@tablename open col_curfetch next from col_cur into @colnamewhile @@fetch_status!=-1beginexec ('update '+@tablename+' set '+@colname+'='''' where '+@colname+' is null' )fetch next from col_cur into @colnam endclose col_curdeallocate col_cur

8樓:風風風姬姬姬

isnull(expression,'') 就是將null換成 0長度字元啊

isnull(expression,0) 才是將null換成 0 呢select isnull(expression,'') from tab;

你的資料型別是數值型,替換後將會將空字元值隱式轉換為0。

無論什麼值,用isnull函式轉換後都要根據原有值型別匹配。

mysql中查詢一個表,把結果中的7替換成文字,請寫出sql語句

9樓:石頭

7是一個欄位嗎?還是一個值?值的話就case when吧 case when a=7 then '文字' else a

10樓:匿名使用者

select replace('123457' ,'7','愛')

要這樣?

如何在查詢語句中把空值(null),輸出為0?

11樓:娛樂小八卦啊

mysql可用:

select cource.c_id,cource.c_name,cource.

c_num,ifnull(student.count_c_id,'lattice') from cource

left join

(select c_id,count(s_id) as count_c_id from cource_student group by c_id) as student

on cource.c_id=student.c_id;

在遇到多張表查詢時,很可能查一個關聯數值時,並沒有這條關聯記錄,所以查詢到的結果是null,通常需要把這個結果處理成0或者其他。這時候就用isnull(欄位,0)。

擴充套件資料

sql null 值

null 值是遺漏的未知資料。預設地,表的列可以存放 null 值。

null 值的處理方式與其他值不同。

null 用作未知的或不適用的值的佔位符。

註釋:無法比較 null 和 0;它們是不等價的。

sql之null、空字串、0的區別:

1、'' 表示空字串,判斷'' 用  ='' 或 <>'' ,

2、null表示空值,數值未知,沒有兩個相等的空值,判斷用 is null 或 is not null

例如:tran_heating_id_!=5 想篩選出所有tran_heating_id_不是5的客戶資訊,但是這樣並不能篩出tran_heating_id_為null的客戶資訊

(因為null是值不確定的情況),需要用is null篩選。

3、0表示值為『0』。

12樓:賓士

利用null函式:

sqlserver: isnull(欄位,0)oracle: nvl(欄位,0)access:

iif(isnull(欄位),0,欄位)mysql: ifnull(欄位,0);

---以上,希望對你有所幫助。

13樓:我tm不管

select isnull(a,0) from table

14樓:

isnull(a,0)

或者case a when null then 0 else a end

15樓:匿名使用者

不可能的,null與0不同。

sql查詢欄位是空的語句並且空值用0代替怎麼寫?

16樓:sql的藝術

--列是字元型別的

select isnull(列名,'0') as 列名 from 表名

--列是數字型別的

select isnull(列名,0) as 列名 from 表名

17樓:匿名使用者

oracle資料庫用nvl(column,'為空時的值')qlserver資料庫用isnull() 用法同上示例:表名value,其中有的欄位是value3update value set value3=nvl(value3,0);

我的絕對正確,還有問題hi我!

18樓:

select isnull(欄位,0)from 表

如果查詢多列,在前面加入列名

19樓:匿名使用者

用isnull函式:

select isnull(欄位,0) from table

20樓:秋梵高明

sqlserver

select isnull(欄位,0) from tableoracle

select decode(欄位,null,0,欄位) from table

21樓:

select xx = 0 from table where xx is null

22樓:

select iif(欄位="",0,欄位) as 欄位 from table

mysql 環境 sql update語句-把table中一個欄位中所有為null的數值改為0(用一條sql語句)

23樓:匿名使用者

更新表中設定狀態= 1,季銨鹽= 41其中id之間的11和15

24樓:

語句解釋:

update 表名 ---更新表

set state = '0' ---設定更新結果where state is null ---判斷state是否為null 用 is null 判斷

mysql中查詢一個表,把結果中的null替換成0,怎麼寫出sql語句?

25樓:好像是夢

1、mssql: isnull()

語法isnull ( check_expression , replacement_value )

引數check_expression

將被檢查是否為 null的表示式。check_expression 可以是任何型別的。

replacement_value

在 check_expression 為 null時將返回的表示式。replacement_value 必須與 check_expresssion 具有相同的型別。

返回型別

返回與 check_expression 相同的型別。

註釋如果 check_expression 不為 null,那麼返回該表示式的值;否則返回 replacement_value。

2、oracle: nvl()

語法nvl(eexpression1, eexpression2)

引數eexpression1, eexpression2

如果 eexpression1 的計算結果為 null 值,則 nvl() 返回 eexpression2。如果 eexpression1 的計算結果不是 null 值,則返回 eexpression1。eexpression1 和 eexpression2 可以是任意一種資料型別。

如果 eexpression1 與 eexpression2 的結果皆為 null 值,則 nvl( ) 返回 null

mysql更新表,a表中xuhao欄位順序不定

select group concat a order by a asc from a group by b 在mysql 中如何查詢某欄位值在幾張表中出現的次數?利用mysql中的 的聚合函式 count 可以實現這個功能,例如需要查詢data表中name出現次數最多版的記錄,可以先按照group...

mysql一張表中如何查詢某個欄位最長值的那條記錄

1 一般查詢語句 select lcontent from caiji ym liuyan 查詢資料 2 有些時候需要查詢某個欄位的長度為多少時候才顯示資料 sql語句 select lcontent from caiji ym liuyan where length lcontent 40 ps ...

mysql查詢欄位的值在哪個表,mysql查詢一個欄位的值在哪個表

如下 select table schema,table name from information schema.columns where column name col1 col1為子段名版。權 mysql檢視欄位在哪個表中 檢視欄位在哪個資料庫的哪張表中 use information sc...