The CREATE TABLE ` employee ` (
` ID ` int (11), NOT NULL auto_increment,
` DEPT_ID ` int (11) NOT NULL,
` NAME ` varchar (20) NOT NULL,
PRIMARY KEY (` ID `),
The KEY ` FK_EMP_DEPT ` (` DEPT_ID `),
The CONSTRAINT ` FK_EMP_DEPT ` FOREIGN KEY (` DEPT_ID `) REFERENCES ` department ` (` ID `),
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
The CREATE TABLE ` department ` (
` ID ` int (11), NOT NULL auto_increment,
` NAME ` varchar (50) NOT NULL,
The PRIMARY KEY (` ID `)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CodePudding user response:
Select count (id), DEPT_ID from the employee GROUP BY DEPT_ID;CodePudding user response:
Through group department id query count, it is concluded that the number of each department