Topic requirements:
①: Check the information of all employees in the table
②: Query the department numbers of the departments to which all employees belong, and do not display duplicate department numbers
③: Find the number of all employees
④: List the highest and lowest wages
⑤: List the average salary and total salary of employees
⑥: Create a new table with only employee number, name and work participation, named work date table
⑦: Display the age of all female employees
⑧: List the employee number, name and date of birth of all employees surnamed Liu
⑨: List the names and working dates of employees born before 1960
⑩: List the department numbers and the total number of people whose total number is greater than 4
I put the table creation information here directly, just copy and paste if you need it.
CREATE TABLE `worker` (
`department number` int(11) NOT NULL,
`employee number` int(11) NOT NULL,
`working hours` date NOT NULL,
`salary` float(8,2) NOT NULL,
`politics face` varchar(10) NOT NULL DEFAULT 'people',
`name` varchar(20) NOT NULL,
`date of birth` date NOT NULL,
PRIMARY KEY (`employee number`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC ;
INSERT INTO `worker` (`department number`, `employee number`, `working hours`, `salary`, `political status`, `name`, `date of birth`) VALUES (101, 1001, '
2015-5 -4', 3500.00, 'People', 'Zhang San', '1990-7-1');
INSERT INTO `worker` (`Department Number`, `Employee Number`, `Working Hours`, `Salary`, ` Political profile`, `Name`, `
Date of birth`) VALUES (101, 1002, '2017-2-6', 3200.00, 'members', 'Lisi', '1997-2-8');
INSERT INTO ` worker` (`department number`, `employee number`, `working hours`, `salary`,`political affiliation`, `name`, `birth
Date`) VALUES (102, 1003, '2011-1-4', 8500.00, 'Party member', 'Wang Liang', '1983-6-8');
INSERT INTO `worker` (`Department number`, `Worker Number`, `Working hours`, `Salary`, `Political status`, `Name`, `
Date of birth`) VALUES (102, 1004, '2016-10-10', 5500.00, 'People', 'Zhao Liu' , '1994-9-5');
INSERT INTO `worker` (`department number`, `employee number`, `working hours`, `salary`, `political status`, `name`, `date of birth`)
VALUES (102, 1005, '2014-4-1', 4800.00, 'Party member', 'Qianqi', '1992-12-30');
INSERT INTO `worker` (`department number`, `employee number`, ` Working time`, `Salary`, `Political status`, `Name`, `
Date of birth`) VALUES (102, 1006, '2017-5-5', 4500.00, 'Party member', 'Sun Ba', '1996- 9-2');
Problem solving process:
①: Check the information of all employees in the table
select * from worker
②: Query the department numbers of the departments to which all employees belong, and do not display duplicate department numbers
select DISTINCT `department number` from worker
③: Find the number of all employees
select COUNT(*) from worker
④: List the highest and lowest wages
select MAX(`salary`) as maximum salary, min(`salary`) as minimum salary from worker
⑤: List the average salary and total salary of employees
select sum(`salary`),avg(`salary`) from worker
⑥: Create a new table with only employee number, name and work participation, named work date table
create table `working date table` select `employee number`,`name`,`working hours` from work
⑦: Display the age of all female employees
⑧: List the employee number, name and date of birth of all employees surnamed Liu
select `employee number`, `name`, `date of birth` from worker where `name` like 'Li%'
⑨: List the names and working dates of employees born before 1960
select `Date of Birth` from worker where YEAR(`Date of Birth`) < 1960
⑩: List the department numbers and the total number of people whose total number is greater than 4
select `Department Number`, count(*) as the total number of people in the department from worker group by `Department Number`
HAVING COUNT(*)>4