#创建一个数据库
create database ganxinchuan;
#在数据库中创建以下三个表,雇员表,部门表,工资表,数据类型,宽度根据实际需要进行设置
#雇员表 employee 雇员编号 empid 姓名 name 性别 sex 职称title 出生日期birthday 所在部门编号depid 雇员编号为主键,部门编号为外键
#部门表 department 部门编号 depid 部门名称depname 部门编号为主键
#工资表 salary 雇员编号empid 基本工资basesalary 职务工资titlesalary 扣除deduction 雇员编号为外键
数据表:
雇员表(employee):雇员编号(empid,主键),姓名(name),性别(sex),职称(title),出生日期(birthday),所属部门(depid)
部门(department):部门编号(depid,主键),部门名称(depname)
工资表(salary):雇员编号(empid),基本工资(basesalary),职务工资(titlesalary),扣除(deduction)
create table emoloyee (
empid varchar(5),
name varchar(10),
sex char(3),
title varchar(20),
birthday date,
depid varchar(4) );
insert into emoloyee
values('1001','张三','男','高级工程师','1975-1-1','111'),
('1002','李四','女','助工','1985-1-1','111'),
('1003','王五','男','工程师','1978-11-11','222'),
('1004','赵六','男','工程师','1979-1-1','222');
create table department (
depid varchar(4),
depname varchar(20));
insert into department values('111','生产部'),('222','销售部'),('333','人事部');
create table salary(
empid varchar(5),
basesalary int ,
titlesalary int,
deduction int);
insert into salary values('1001',2200,1100,200),
('1002',1200,200,100), ('1003',1900,700,200),('1004',1950,700,150);
#修改表结构,在部门表中添加部门简介字段
alter table department add depinfo varchar(35);
desc department;
#将李四的职称改成工程师,并将他的基本工资改为2000,职务工资700
update employee,salary set employee.title='工程师',salary.basesalary=2000,salary.titlesalary=700
where employee.name='李四' and employee.empid = salary.empid;
select * from employee;
select * from salary;
#删除人事部门的记录
delete from department where department.depname = '人事部';
select * from department;
#查询出部门的雇员编号,实发工资,应发工资
select empid,basesalary+titlesalary as 应发工资,basesalary+titlesalary-deduction as
实发工资 from salary;
#查询姓张的且年龄小于40
select * from employee where name like '张%' and 2018-birthday < 40;
#查询雇员的编号,姓名,职称,部门名称,实发工资
select employee.empid,employee.name,department.depname,basesalary+titlesalary-deduction
as '实发工资' from employee,department,salary
where employee.empid = salary.empid and employee.depid = department.depid;
#查询销售部门的雇员姓名,基本工资
select employee.name,salary.basesalary from employee,salary
where employee.empid = salary.empid and employee.depid = (
select department.depid from department
where department.depname = '销售部')
#统计各职称的人数
select title,count(title) from employee group by title;
#统计各部门的部门名称,实发工资和平均工资
select department.depname as '部门名称',sum(basesalary)+sum(titlesalary)-sum(deduction) as '实发工资',
avg(basesalary)+avg(titlesalary)-avg(deduction) as '平均工资'
from department,salary,employee
where department.depid = employee.depid
and employee.empid = salary.empid
group by '部门名称';
select department.depname as '部门',employee.name as '员工名',salary.basesalary as '基本工资',salary.titlesalary '职位工资'
,salary.deduction as '扣除'
from department,employee,salary
where department.depid = employee.depid and employee.empid = salary.empid
-- group by depname;
#查询比销售部门所有员工基本工资都高的雇员信息
select name,sex,title,birthday from employee,salary
where employee.empid = salary.empid and salary.basesalary > (
select max(salary.basesalary) from salary,department,employee
where department.depname = '销售部'
and department.depid = employee.depid
and employee.empid = salary.empid
)
财务管理系统-数据库模块
最新推荐文章于 2022-11-10 17:42:08 发布