财务管理系统-数据库模块



#创建一个数据库
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
)

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
import java.sql.*; public class DataBaseConnection { static{ //2005 //String DBDRIVER="com.microsoft.jdbc.sqlserver.SQLServerDriver";//2000 } public static Connection getConn(){ String DBDRIVER="com.microsoft.sqlserver.jdbc.SQLServerDriver"; String DBURL="jdbc:sqlserver://localhost:1433;DatabaseName=cwgl"; Connection conn=null; try { Class.forName(DBDRIVER); conn=DriverManager.getConnection(DBURL,"sa","1"); } catch (Exception e) { e.printStackTrace(); } return conn; } public static void closeConn(Connection conn){ try { conn.close(); conn=null; } catch (SQLException e) { e.printStackTrace(); } } public static Statement getStmt(Connection conn){ Statement stmt=null; try { stmt=conn.createStatement(); } catch (SQLException e) { e.printStackTrace(); } return stmt; } public static void closeStmt(Statement stmt){ try { stmt.close(); stmt=null; } catch (SQLException e) { e.printStackTrace(); } } public static PreparedStatement getpStmt(Connection conn,String sql){ PreparedStatement pStmt=null; try { pStmt=conn.prepareStatement(sql); } catch (SQLException e) { e.printStackTrace(); } return pStmt; } public static void closePstmt(Statement pstmt){ try { pstmt.close(); pstmt=null; } catch (SQLException e) { e.printStackTrace(); } } public static ResultSet getRs(Statement stmt,String sql){ ResultSet rs=null; try { rs=stmt.executeQuery(sql); } catch (SQLException e) { e.printStackTrace(); } return rs; } public static void closeRs(ResultSet rs){ try { rs.close(); rs=null; } catch (SQLException e) { e.printStackTrace(); } } }
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值