欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Mysql查詢以某"字符串"開頭的查詢方式

 更新時(shí)間:2022年08月29日 11:17:02   作者:第六序列  
這篇文章主要介紹了Mysql查詢以某"字符串"開頭的查詢方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

Mysql查詢以某"字符串"開頭的查詢

查詢不以某個(gè)或者某些字符串為開頭的字符串

1、使用left()函數(shù)

select * from order where left(id,2)<>"AB";

2、使用like

select * from order where id not like "%AB%";

查詢以某個(gè)或者某些字符串為開頭的字符串

1、使用left()函數(shù)

select * from order where left(id,2)="AB";

2、使用like

select * from order where id like "%AB%";

Mysql查詢條件字符串類型 = 0

假如有表A

idint
namevarchar

A表中有以下數(shù)據(jù)

idname
1張三
2李四
32王五

執(zhí)行以下sql:

select * from A where name = 0;

會(huì)將id=1,id=2的結(jié)果返回。

select * from A where name = 2;

會(huì)將id=3的結(jié)果返回。

為什么?

因?yàn)镸ysql “Strings are automatically converted to numbers and numbers to strings as necessary”,字符串自動(dòng)轉(zhuǎn)換為數(shù)字,數(shù)字自動(dòng)轉(zhuǎn)換為字符串 。

當(dāng)字符串和數(shù)字比較時(shí),mysql會(huì)從字符串開頭截取數(shù)字,沒(méi)有數(shù)字的直接轉(zhuǎn)成0。

不建議不同類型的數(shù)據(jù)進(jìn)行比較。

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論