實(shí)際查詢中盛正,通常不會(huì)檢索所有行映屋,需要對(duì)數(shù)據(jù)進(jìn)行篩選過濾客峭,選出符合我們需要條件的數(shù)據(jù)逸月。
sql中的數(shù)據(jù)過濾通過where子句中指定的搜索條件進(jìn)行
where子句操作符
檢查單個(gè)值
select prod_name, prod_price
from products
where prod_price = 3.49;
select prod_name,prod_price
from products
where prod_price < 10;
select vend_id, prod_name
from products
where vend_id <> 'DLL01';
select vend_id, prod_name
from products
where vend_id != 'DLL01';
范圍值檢查
select prod_name,prod_price
from products
where prod_price between 5 and 10;
檢查空值
select prod_name
from products
where prod_name is null;
組合where子句
and or操作符
select prod_name, prod_price
from products
where vend_id = 'DLL01' OR vend_id = 'BRS01'
and prod_price >= 10;
select prod_name, prod_price
from products
where (vend_id = 'DLL01' OR vend_id = 'BRS01')
and prod_price >= 10;
in操作符
select prod_name, prod_price
from products
where vend_id in( 'DLL01' , 'BRS01');
not 操作符
select prod_name
from products
where not vend_id = 'DLL01'
order by prod_name;
使用通配符進(jìn)行過濾
使用like操作符進(jìn)行通配搜索
%表示字符任意出現(xiàn)的次數(shù)瘦穆,fish開頭的字符
select prod_id,prod_name
from products
where prod_name like 'Fish%';
與%類似纪隙,但只匹配單個(gè)字符
select prod_id,prod_name
from products
where prod_name like '__ inch teddy bear';
[]通配符用來匹配字符集,必須匹配方括號(hào)中的某一個(gè)字符
select cust_contact
from customers
where cust_contact like '[JM]%';