MySQL的謂詞是一種用于過濾和限制查詢結果的語句。謂詞允許您根據特定的條件篩選出查詢中的行,以便獲得更有用和有意義的結果。以下是一些最常用的MySQL謂詞:
-- WHERE 謂詞 SELECT * FROM orders WHERE order_date BETWEEN '2019-01-01' AND '2019-01-31'; -- AND 和 OR 謂詞 SELECT * FROM customers WHERE city = 'New York' AND state = 'NY'; SELECT * FROM customers WHERE city = 'New York' OR state = 'NY'; -- IN 和 NOT IN 謂詞 SELECT * FROM products WHERE category_id IN (1, 3, 5); SELECT * FROM products WHERE category_id NOT IN (2, 4, 6); -- LIKE 和 NOT LIKE 謂詞 SELECT * FROM employees WHERE last_name LIKE 'Sm%'; SELECT * FROM employees WHERE last_name NOT LIKE '%th'; -- IS NULL 和 IS NOT NULL 謂詞 SELECT * FROM customers WHERE email IS NULL; SELECT * FROM customers WHERE email IS NOT NULL;
使用MySQL謂詞可以快速有效地查詢和篩選數據庫中的數據。這些謂詞可以組合使用,以便更細致和具體的過濾查詢結果。