在SQL中,SELECT语句用于从数据库表中检索数据。以下是使用SELECT语句查询数据的基本语法和示例:
SELECT column1, column2, ... FROM table_name WHERE condition;
假设我们有一个名为employees的表,包含以下列:id, name, age, department。
SELECT * FROM employees;
SELECT name, age FROM employees;
SELECT * FROM employees WHERE age > 30;
SELECT * FROM employees WHERE age > 30 ORDER BY age DESC;
SELECT department, COUNT(*) as employee_count FROM employees WHERE age > 30 GROUP BY department;
SELECT department, AVG(age) as average_age FROM employees WHERE age > 30 GROUP BY department;