SQL學習(四)條件查詢(字串型別屬性篩選)

2021-10-23 04:30:57 字數 1473 閱讀 1703

本節主要使用where語句篩選字串型別的屬性。

like(模糊查詢) 和 %(萬用字元)是字串相關查詢的兩個關鍵字。

條件查詢語句還是where語句

select column, another_column, …

from mytable

where condition

and/or another_condition

and/or …;

operator(關鍵字)

sql example(例子)

=col_name = 「abc」

!=col_name != 「abcd」

like

col_name like 「abc」

not like

col_name not like 「abcd」

%col_name not in (1, 3, 5)

_col_name like 「an_」

in (…)

col_name in (「a」, 「b」, 「c」)

not in (…)

col_name not in (「d」, 「e」, 「f」)

xuesql 8.8¥xuesql平台作者應該收。

不過我們可以自己猜猜看sql語句怎麼寫,借助人家這個平台來練習也可以。

select * from movies 

where title like "%toy story%";

select * from movies 

where director like "john lasseter";

select * from movies 

where director not like "john lasseter";

select * from movies 

where title like "%wall-%";

select * from movies

where year = 1998

nad title = "蟲蟲危機";

select title,director,year from movies

where director like "pete%";

」n%「,表示以n開頭的

」%n「,表示以n結尾的

select * from movies

where director like "john lasseter"

and year > 1000

and title link "car%"

and title link "toy story%"

順便查一下什麼是千禧年。

MySQL學習之路(四) 條件查詢

分類 按條件表示式篩選 簡單條件運算子 按邏輯表示式篩選 邏輯運算子 and or not 模糊查詢 like between and in is null is not nill select 列名1 列名2 from 表名 where 條件表示式select 列名1 列名2 from 表名 wh...

java學習 四 條件語句 if else

條件語句的條件要返回乙個布林值,if語句包含乙個布林表示式和一條或多條語句,語法如下 if 布林表示式 實例如圖 if語句後面可以跟else語句,當if語句的布林表示式值為false時,else語句塊會被執行。語法如下 if 布林表示式 else 實例如圖 在if語句後面也可以跟else if語句,...

python基礎學習(四) 條件和分支

1.成績分類三種方法的區別 根據成績,進行分類abcde 法1 score int input 請輸入分數 if 100 score 90 print a if 90 score 80 print b if 80 score 70 print c if 70 score 60 print d if ...