組合WHERE AND操做符:sql
1.AND用在WHERE子句中的關鍵字,用來指示知足全部給定條件的行,能夠添加多個過濾條件,每一個添加一條使用一個ANDcode
SELECT vend_id, prod_price, prod_name FROM products WHERE vend_id = 1003 AND prod_price <= 10;
組合WHERE OR操做符:class
1.OR用在WHERE子句中的關鍵字,用來指示知足任意條件的行co
SELECT vend_id, prod_price, prod_name FROM products WHERE vend_id = 1003 OR vend_id = 1002;
組合WHERE 計算次序:
1.WHERE可包含任意數目的AND/OR操做符,容許二者結合進行復雜和高級的過濾,可是AND的優先級更高,因此須要圓括號明確分組相應的操做符
SELECT vend_id, prod_price, prod_name FROM products WHERE (vend_id = 1002 OR vend_id = 1003) AND prod_price >= 10;
組合WHERE IN操做符:
1.圓括號結合IN操做符用來指定條件範圍,範圍中的每一個條件均可以進行匹配,IN操做符的速度比OR操做符執行更快,並且IN的最大優勢是能夠包含其它的SELECT語句,使得能夠動態建立WHERE子句
SELECT vend_id, prod_name, prod_price FROM products WHERE vend_id in (1002, 1003) ORDER BY prod_name;
組合WHERE NOT NOT操做符:
1.WHERE子句中的NOT操做符有且只有一個功能,否認它以後所跟的任何條件
SELECT vend_id, prod_name, prod_price FROM products WHERE vend_id not in (1002, 1003) ORDER BY prod_name;