mysql過濾資料 MySQL過濾資料

2021-10-18 01:45:59 字數 1918 閱讀 9195

1. mysql過濾資料

使用where子句

select prod_name, prod_price from products where prod_price = 2.50;

檢查單個值

select prod_name, prod_price from products where prod_name = 'fuses';

select prod_name, prod_price from products where prod_price < 10;

select prod_name, prod_price from products where prod_price <= 10;

不匹配檢查

select vend_id, prod_name from products where vend_id <> 1003;

select vend_id, prod_name from products where vend_id != 1003;

範圍值檢查

select prod_name, prod_price from products where prod_price between 5 and 10;

空值檢查

select cust_id from customers where cust_email is null;

1. where 執行匹配時預設不區分大小寫

2. is null 判斷空值

2. mysql資料過濾

組合where子句

and操作符

select prod_id, prod_price, prod_name from products where vend_id = 1003 and prod_price <= 10;

or操作符

select prod_name, prod_price, vend_id from products where vend_id = 1002 or vend_id = 1003;

計算次序

select prod_name, prod_price, vend_id from products where vend_id = 1002 or vend_id = 1003 and prod_price >= 10;

in操作符

select prod_name, prod_price, vend_id from products where vend_id in (1002, 1003) order by prod_name;

not操作符

select prod_name, prod_price, vend_id from products where vend_id not in (1002, 1003) order by prod_name;

1. and在計算次序中優先順序高於or

2. in使用的好處

1) 語法清楚更直觀

2) 計算次序更容易管理

3) 比or操作符執行快

4) 可以包含其他select語句,可以更動態地建立where子句

3. not關鍵字

not支援in、between、exists子句取反

3. mysql用萬用字元進行過濾

like操作符

百分號(%)萬用字元

%表示任何字元出現任意次數

select prod_id, prod_name from products where prod_name like '%anvil%';

select prod_id, prod_name from products where prod_name like 's%e';

下劃線(_)萬用字元

_表示任何字元出現一次

select prod_id, prod_name from products where prod_name like '_ ton anvil';

mysql過濾範圍 MySQL 過濾資料

使用select語句的where子句指定搜尋條件 在select語句中,資料根據where子句中指定的搜尋條件進行過濾,where子句在表名之後給出 select 列名1,列名2 from 表名 where 條件 條件為列中資料的特定值 where子句位置 select from where ord...

mysql過濾 MySQL必知必會 資料過濾

組合where子句 1.1 and操作符 1.2 or操作符 1.3 計算次序 in 操作符 not操作符 1.1 and操作符 mariadb test select id,age,province from user where age 30 and province 北京 id age pro...

mysql括號被過濾 MySQL之資料過濾

資料過濾 如何組合where子句以建立功能更強的更高階的搜尋條件。還將學習如何使用not和in操作符。1.and操作符 and操作符select vend id,prod id,prod price,prod name from products where vend id 1003 and pro...