在 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 语句时,要确保语法正确且符合数据库表结构。