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)

`

相关推荐
m0_7482448334 分钟前
StarRocks 排查单副本表
大数据·数据库·python
C++忠实粉丝44 分钟前
Redis 介绍和安装
数据库·redis·缓存
wmd131643067121 小时前
将微信配置信息存到数据库并进行调用
数据库·微信
是阿建吖!1 小时前
【Linux】基础IO(磁盘文件)
linux·服务器·数据库
凡人的AI工具箱1 小时前
每天40分玩转Django:Django国际化
数据库·人工智能·后端·python·django·sqlite
ClouGence1 小时前
Redis 到 Redis 数据迁移同步
数据库·redis·缓存
m0_748236582 小时前
《Web 应用项目开发:从构思到上线的全过程》
服务器·前端·数据库
苏三说技术2 小时前
Redis 性能优化的18招
数据库·redis·性能优化
Tttian6222 小时前
基于Pycharm与数据库的新闻管理系统(2)Redis
数据库·redis·pycharm
做梦敲代码3 小时前
达梦数据库-读写分离集群部署
数据库·达梦数据库