把employee表中数据按照department分类细分成子表(12张表)sql语句
时间: 2023-07-04 20:28:22 浏览: 109
可以使用以下 SQL 语句将 employee 表中的数据按照 department 分类细分成子表:
```sql
-- 创建子表
CREATE TABLE employee_dept1 AS
SELECT * FROM employee WHERE department = 'dept1';
CREATE TABLE employee_dept2 AS
SELECT * FROM employee WHERE department = 'dept2';
-- 依此类推,创建剩余的子表
CREATE TABLE employee_dept3 AS
SELECT * FROM employee WHERE department = 'dept3';
CREATE TABLE employee_dept4 AS
SELECT * FROM employee WHERE department = 'dept4';
CREATE TABLE employee_dept5 AS
SELECT * FROM employee WHERE department = 'dept5';
CREATE TABLE employee_dept6 AS
SELECT * FROM employee WHERE department = 'dept6';
CREATE TABLE employee_dept7 AS
SELECT * FROM employee WHERE department = 'dept7';
CREATE TABLE employee_dept8 AS
SELECT * FROM employee WHERE department = 'dept8';
CREATE TABLE employee_dept9 AS
SELECT * FROM employee WHERE department = 'dept9';
CREATE TABLE employee_dept10 AS
SELECT * FROM employee WHERE department = 'dept10';
CREATE TABLE employee_dept11 AS
SELECT * FROM employee WHERE department = 'dept11';
CREATE TABLE employee_dept12 AS
SELECT * FROM employee WHERE department = 'dept12';
```
以上 SQL 语句将按照 department 分类细分成 12 张子表,每个子表对应一个 department。注意,这种方式可能会导致数据冗余,因此需要根据实际情况进行评估。
阅读全文