mysql第二次作业

sql 复制代码
#(1)
mysql> select * from t_worker;
+---------------+---------+-------------+----------+----------+--------+------------+
| department_id | work_id | worker_date | wages    | politics | name   | borth_date |
+---------------+---------+-------------+----------+----------+--------+------------+
|           101 |    1001 | 2015-05-04  |  7500.00 | 群众     | 张春燕 | 1990-07-01 |
|           101 |    1002 | 2019-02-06  |  5200.00 | 团员     | 李名博 | 1997-02-08 |
|           102 |    1003 | 2008-01-04  | 10500.00 | 党员     | 王博涵 | 1983-06-08 |
|           102 |    1004 | 2016-10-10  |  5500.00 | 群众     | 赵小军 | 1994-09-05 |
|           102 |    1005 | 2014-04-01  |  8800.00 | 党员     | 钱有财 | 1992-12-30 |
|           103 |    1006 | 2019-05-05  |  5500.00 | 党员     | 孙菲菲 | 1996-09-02 |
+---------------+---------+-------------+----------+----------+--------+------------+
6 rows in set (0.00 sec)

#(2)
mysql> select distinct department_id from t_worker;
+---------------+
| department_id |
+---------------+
|           101 |
|           102 |
|           103 |
+---------------+
3 rows in set (0.00 sec)

#(3)
mysql> select count(1) from t_worker;
+----------+
| count(1) |
+----------+
|        6 |
+----------+
1 row in set (0.00 sec)

#(4)
mysql> select max(wages) '最高工资',min(wages) '最低工资' from t_worker;
+----------+----------+
| 最高工资 | 最低工资 |
+----------+----------+
| 10500.00 |  5200.00 |
+----------+----------+
1 row in set (0.00 sec)

#(5)
mysql> select avg(wages) '平均工资',sum(wages) '总工资' from t_worker;
+-------------+----------+
| 平均工资    | 总工资   |
+-------------+----------+
| 7166.666667 | 43000.00 |
+-------------+----------+
1 row in set (0.00 sec)

#(6)
mysql> create table work_date(worker_id int(11) not null comment '部门号',worker_name varchar(20) not null comment '姓名',worker_date date not null comment '参加工作');
Query OK, 0 rows affected, 1 warning (0.03 sec)

mysql> desc work_date;
+-------------+-------------+------+-----+---------+-------+
| Field       | Type        | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| worker_id   | int         | NO   |     | NULL    |       |
| worker_name | varchar(20) | NO   |     | NULL    |       |
| worker_date | date        | NO   |     | NULL    |       |
+-------------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

#(7)
mysql> select work_id,borth_date,timestampdiff(year,borth_date,curdate()) '党员年龄' from t_worker;
+---------+------------+----------+
| work_id | borth_date | 党员年龄 |
+---------+------------+----------+
|    1001 | 1990-07-01 |       34 |
|    1002 | 1997-02-08 |       27 |
|    1003 | 1983-06-08 |       41 |
|    1004 | 1994-09-05 |       29 |
|    1005 | 1992-12-30 |       31 |
|    1006 | 1996-09-02 |       27 |
+---------+------------+----------+
6 rows in set (0.00 sec)


#(8)
mysql> select name,wages from t_worker where wages between 4000 and 8000;
+--------+---------+
| name   | wages   |
+--------+---------+
| 张春燕 | 7500.00 |
| 李名博 | 5200.00 |
| 赵小军 | 5500.00 |
| 孙菲菲 | 5500.00 |
+--------+---------+
4 rows in set (0.00 sec)

#(9)
mysql> select name from t_worker where name like '孙%' or name like '李%' ;
+--------+
| name   |
+--------+
| 李名博 |
| 孙菲菲 |
+--------+
2 rows in set (0.00 sec)

#(10)
mysql> select work_id,name from t_worker where department_id in(102,103) and politics!='党员';
+---------+--------+
| work_id | name   |
+---------+--------+
|    1004 | 赵小军 |
+---------+--------+
1 row in set (0.00 sec)

#(11)
mysql> select * from t_worker order by borth_date;
+---------------+---------+-------------+----------+----------+--------+------------+
| department_id | work_id | worker_date | wages    | politics | name   | borth_date |
+---------------+---------+-------------+----------+----------+--------+------------+
|           102 |    1003 | 2008-01-04  | 10500.00 | 党员     | 王博涵 | 1983-06-08 |
|           101 |    1001 | 2015-05-04  |  7500.00 | 群众     | 张春燕 | 1990-07-01 |
|           102 |    1005 | 2014-04-01  |  8800.00 | 党员     | 钱有财 | 1992-12-30 |
|           102 |    1004 | 2016-10-10  |  5500.00 | 群众     | 赵小军 | 1994-09-05 |
|           103 |    1006 | 2019-05-05  |  5500.00 | 党员     | 孙菲菲 | 1996-09-02 |
|           101 |    1002 | 2019-02-06  |  5200.00 | 团员     | 李名博 | 1997-02-08 |
+---------------+---------+-------------+----------+----------+--------+------------+
6 rows in set (0.00 sec)

#(12)
mysql> select work_id,name from t_worker order by wages desc limit 3;
+---------+--------+
| work_id | name   |
+---------+--------+
|    1003 | 王博涵 |
|    1005 | 钱有财 |
|    1001 | 张春燕 |
+---------+--------+
3 rows in set (0.00 sec)

#(13)
mysql> select count(1),department_id from t_worker where politics='党员' group by department_id;
+----------+---------------+
| count(1) | department_id |
+----------+---------------+
|        2 |           102 |
|        1 |           103 |
+----------+---------------+
2 rows in set (0.00 sec)

#(14)
mysql> select sum(wages) '部门总工资',round(avg(wages),2) '平均工资',department_id from t_worker group by department_id;
+------------+----------+---------------+
| 部门总工资 | 平均工资 | department_id |
+------------+----------+---------------+
|   12700.00 |     6350 |           101 |
|   24800.00 |  8266.67 |           102 |
|    5500.00 |     5500 |           103 |
+------------+----------+---------------+
3 rows in set (0.00 sec)

#(15)
mysql> select department_id,count(1) from t_worker group by department_id having count(1)>=3;
+---------------+----------+
| department_id | count(1) |
+---------------+----------+
|           102 |        3 |
+---------------+----------+
1 row in set (0.00 sec)

`

相关推荐
呼啦啦呼啦啦啦啦啦啦1 小时前
在win10环境部署opengauss数据库(包含各种可能遇到的问题解决)
数据库
苹果醋31 小时前
前端面试之九阴真经
java·运维·spring boot·mysql·nginx
不是二师兄的八戒1 小时前
MYSQL索引优化
mysql
m0_748230211 小时前
mysql约束和高级sql
数据库·sql·mysql
刘艳兵的学习博客1 小时前
刘艳兵-DBA046-ASSM表空间的全表扫描范围由哪些因素综合确定?
数据库·sql·oracle·刘艳兵
2401_857636391 小时前
实验室管理技术革新:Spring Boot系统
数据库·spring boot·后端
生活很暖很治愈2 小时前
C51数字时钟/日历---LCD1602液晶显示屏
数据库·单片机·mongodb
YONG823_API2 小时前
1688商品数据采集API的测试对接步骤分享(提供免费测试key)
开发语言·数据库·爬虫·python·数据挖掘
码上一元2 小时前
掌握 Spring 事务管理:深入理解 @Transactional 注解
数据库·spring
程序猿毕设源码分享网3 小时前
基于springboot停车场管理系统源码和论文
数据库·spring boot·后端