Mysql数据库小练习

  1. 安装mysql数据库

  2. 创建一个mydb1数据库,并查看。

  3. 创建一张表,表名employee ,表结构如下

*字段名**字段类型**长度*
id整形11
name字符串20
sex字符串10
birthday日期
salary浮点型10(2位小数)
bonus浮点型10(2位小数)
department字符串20
resume字符串
  1. 插入如下数据
*id**name**sex**birthday**salary**bonus**department**resume*
1杨过male1980-11-252000100总裁办good body
2李逍遥male1980-04-251000200研发部good body
3小龙女female1978-11-254000100财务部good girl
4阿紫male1981-01-254000400人事部good girl
5王语嫣male1978-12-252000人事部good girl
6赵灵儿female1998-05-252000100人事部good girl
7任盈盈male1968-10-253000500财务部good girl
8张三丰male1968-10-252000100财务部good body
9张无忌male1988-10-253000100研发部good body
  1. 将研发部员工的薪水修改为2500

    update employee set salary=2500 WHERE department='研发部';
    
  2. 将姓名为”阿紫”的员工薪水修改为3000元。

    update employee set salary=3000 where `name`='阿紫';
    
  3. 将姓名为”赵灵儿”的员工薪水修改为4000元,sex改为female。

    update employee set salary=4000,sex='female' where `name`='赵灵儿';
    
  4. 公司统一给每位员工再发奖金500

    update employee set bonus=bonus+500;
    
  5. 将”张三丰”的薪水在原有基础上增加1000元。

    update employee set salary=salary+1000 WHERE `name`='张三丰';
    
  6. 查询表中所有员工的信息。

    SELECT * from employee;
    
  7. 查询表中所有员工的姓名和对应的薪水。

    SELECT name,salary from employee;
    
  8. 使用汉语展示员工信息。(列名翻译成中文展示)

    SELECT id 编号, name 名字,sex 性别,birthday 生日, salary 薪水,bonus 奖金,department 部门,resume 备注 from employee;
    
  9. 查询姓名为”杨过”的员工的薪水

    SELECT salary FROM employee WHERE name='杨过';
    
  10. 查询姓名为”杨过”的员工的总收入

    SELECT SUM(salary+bonus) from employee where `name`='杨过';
    
  11. 查询薪水大于3000的员工信息

    SELECT * from employee where salary>3000;
    
  12. 查询总收入大于4000的员工的姓名 部门 薪水 奖金

    SELECT name,department,salary,bonus FROM employee where salary+bonus>4000;
    
  13. 查询80后的员工

    SELECT * from employee WHERE birthday>'1980-01-01';
    
  14. 查询所有女性薪水大于4000的员工

    SELECT * from employee WHERE sex='female' and salary>4000;
    
  15. 查询所有女性薪水大于4000的员工按薪水降序排列

    SELECT * from employee WHERE sex='female' and salary>4000 ORDER BY salary DeSC;
    
  16. 查询各个部门员工数量

    SELECT COUNT(*) from employee GROUP BY department;
    
  17. 查询各个部门的员工数量及薪水支出

    SELECT COUNT(*),sum(salary) from employee GROUP BY department;
    
  18. 查询各个部门的员工数量及总支出

    SELECT COUNT(*),sum(salary+bonus) from employee GROUP BY department;
    
  19. 查询公司男性和女性的数量

    SELECT sex,sum(salary+bonus) FROM employee GROUP BY sex;
    
  20. 查询公司男性员工和女性员工的收入总和

    SELECT sum(salary+bonus),sex FROM employee GROUP BY sex;
    
  21. 查询公司中男性员工的收入总和

    SELECT sum(salary+bonus)AS '男生总收入' FROM employee where sex='male';
    
  22. 查询公司中总支出大于9000的部门

    SELECT department,SUM(salary+bonus)AS'count' FROM employee GROUP BY department HAVING count>9000 ;
    
  23. 查询公司中所有”张”姓员工的平均工资

    SELECT AVG(salary) FROM employee where `name` like '张%';
    
  24. 查询公司中”张”姓员工的工资总和

    SELECT sum(salary) FROM employee where `name` like '张%';
    
  25. 查询公司中”张”姓员工的总收入

    SELECT sum(salary+bonus) FROM employee where `name` like '张%';
    
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值