在 SQL 語句中,WHERE
子句用于過濾查詢結果,只返回滿足指定條件的記錄。WHERE
子句通常放在 SELECT
、UPDATE
、DELETE
等語句中,用于限定數據行的范圍。
以下是一些使用 WHERE
子句的示例:
SELECT column1, column2, ...
FROM table_name
WHERE condition;
SELECT * FROM employees
WHERE department_id = 50;
SELECT * FROM employees
WHERE salary <> 3000;
SELECT * FROM employees
WHERE age > 30 AND salary < 5000;
SELECT * FROM employees
WHERE age BETWEEN 25 AND 35;
SELECT * FROM employees
WHERE department_id IN (10, 20, 30);
SELECT * FROM employees
WHERE last_name LIKE 'S%';
SELECT * FROM employees
WHERE department_id = 10 OR department_id = 20;
SELECT * FROM employees
WHERE (department_id = 10 OR department_id = 20) AND salary > 5000;
請根據實際需求編寫適當的 WHERE
子句。注意在編寫 SQL 語句時,要確保語法正確且符合數據庫表結構。