MySQL查询相关内容

server/2025/1/19 7:26:56/

创建员工库和表; 

mysql> create database mydb8_worker;
Query OK, 1 row affected (0.01 sec)mysql> use mydb8_worker;
Database changed
mysql> create table t_worker(-> department_id int(11) not null comment '部门号',-> worker_id int(11) primary key not null comment '职工号',-> worker_date date not null comment '工作时间',-> wages float(8,2) not null comment '工资',-> polotics varchar(10) not null default '群众' comment '政治面貌',-> name varchar(20) not null comment '姓名',-> borth_date date not null comment '出生日期');
Query OK, 0 rows affected, 3 warnings (0.02 sec)mysql> insert into t_worker values(101,1001,'2015-5-4',7500.00,'群众','张春燕','1990-7-1');
Query OK, 1 row affected (0.01 sec)
mysql> insert into t_worker values(101,1002,'2019-2-6',5200.00,'团员','李明博','1997-2-8');
Query OK, 1 row affected (0.01 sec)
mysql> insert into t_worker values(102,1003,'2008-1-4',10500.00,'党员','王博涵','1983-6-8');
Query OK, 1 row affected (0.00 sec)
mysql> insert into t_worker values(102,1004,'2016-10-10',5500.00,'群众','赵小军','1994-9-5');
Query OK, 1 row affected (0.01 sec)
mysql> insert into t_worker values(102,1005,'2014-4-1',8800.00,'党员','钱有才','1992-12-30');
Query OK, 1 row affected (0.00 sec)
mysql> insert into t_worker values(103,1006,'2019-5-5',5500.00,'党员','孙菲菲','1996-9-2');
Query OK, 1 row affected (0.01 sec)

完成对应查询操作。

mysql> select * from t_worker;
+---------------+-----------+-------------+----------+----------+--------+------------+
| department_id | worker_id | worker_date | wages    | polotics | 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)mysql> select distinct department_id from t_worker;
+---------------+
| department_id |
+---------------+
|           101 |
|           102 |
|           103 |
+---------------+
3 rows in set (0.00 sec)mysql> select count(*) from t_worker;
+----------+
| count(*) |
+----------+
|        6 |
+----------+
1 row in set (0.01 sec)mysql> select max(wages) as '最高工资',min(wages) as '最低工资' from t_worker;
+----------+----------+
| 最高工资 | 最低工资 |
+----------+----------+
| 10500.00 |  5200.00 |
+----------+----------+
1 row in set (0.00 sec)mysql> select avg(wages) as '平均工资',sum(wages) as '总工资' from t_worker;
+-------------+----------+
| 平均工资    | 总工资   |
+-------------+----------+
| 7166.666667 | 43000.00 |
+-------------+----------+
1 row in set (0.00 sec)mysql> create table work_date as select worker_id,name,worker_date from t_worker;
Query OK, 6 rows affected (0.02 sec)
Records: 6  Duplicates: 0  Warnings: 0mysql> show tables;
+------------------------+
| Tables_in_mydb8_worker |
+------------------------+
| t_worker               |
| work_date              |
+------------------------+
2 rows in set (0.00 sec)mysql> select name,year(now())-year(borth_date) as '年龄' from t_worker where polotics='党员';
+--------+------+
| name   | 年龄 |
+--------+------+
| 王博涵 |   42 |
| 钱有才 |   33 |
| 孙菲菲 |   29 |
+--------+------+
3 rows in set (0.00 sec)mysql> select name from t_worker where wages between 4000 and 8000;
+--------+
| name   |
+--------+
| 张春燕 |
| 李明博 |
| 赵小军 |
| 孙菲菲 |
+--------+
4 rows in set (0.00 sec)mysql> select name from t_worker where name like '孙%' or name like '李%';
+--------+
| name   |
+--------+
| 李明博 |
| 孙菲菲 |
+--------+
2 rows in set (0.00 sec)mysql> select worker_id,name from t_worker where (department_id<=>102 or department_id<=>103) and polotics!='党员';
+-----------+--------+
| worker_id | name   |
+-----------+--------+
|      1004 | 赵小军 |
+-----------+--------+
1 row in set (0.00 sec)mysql> select * from t_worker order by borth_date;
+---------------+-----------+-------------+----------+----------+--------+------------+
| department_id | worker_id | worker_date | wages    | polotics | 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)mysql> select worker_id,name from t_worker order by wages desc limit 3;
+-----------+--------+
| worker_id | name   |
+-----------+--------+
|      1003 | 王博涵 |
|      1005 | 钱有才 |
|      1001 | 张春燕 |
+-----------+--------+
3 rows in set (0.00 sec)mysql> select department_id,count(worker_id) as '党员人数' from t_worker where polotics='党员' group by department_id;
+---------------+----------+
| department_id | 党员人数 |
+---------------+----------+
|           102 |        2 |
|           103 |        1 |
+---------------+----------+
2 rows in set (0.00 sec)mysql> select department_id,count(*) as '党员人数',round(avg(wages),2) as '平均工资' from t_worker where polotics='党员' group by department_id;
+---------------+----------+----------+
| department_id | 党员人数 | 平均工资 |
+---------------+----------+----------+
|           102 |        2 |     9650 |
|           103 |        1 |     5500 |
+---------------+----------+----------+
2 rows in set (0.01 sec)mysql> select department_id,count(*) as '总人数' from t_worker group by department_id having count(*) >=3;
+---------------+--------+
| department_id | 总人数 |
+---------------+--------+
|           102 |      3 |
+---------------+--------+
1 row in set (0.00 sec)

 

 


http://www.ppmy.cn/server/159570.html

相关文章

网络安全面试题及经验分享

本文内容是i春秋论坛面向专业爱好者征集的关于2023年面试题目和答案解析&#xff0c;题目是真实的面试经历分享&#xff0c;具有很高的参考价值。 shiro反序列化漏洞的原理 Shiro反序列化漏洞的原理是攻击者通过精心构造恶意序列化数据&#xff0c;使得在反序列化过程中能够执…

【2024年华为OD机试】 (B卷,200分)- 区间交集(Java JS PythonC/C++)

一、问题描述 题目解析 问题描述 给定一组闭区间&#xff0c;其中部分区间存在交集。要求&#xff1a; 求出任意两个区间的交集&#xff08;称为公共区间&#xff09;。如果公共区间之间存在交集&#xff0c;则需要合并这些公共区间。最终按升序排列输出合并后的区间列表。…

SparkSQL函数

文章目录 1. SparkSQL函数概述2. SparkSQL内置函数2.1 常用内置函数分类2.2 常用数组函数2.2.1 array()函数1. 定义2. 语法3. 示例 2.3 常用日期与时间戳函数2.4 常见聚合函数2.5 常见窗口函数 3. SparkSQL自定义函数3.1 自定义函数分类3.2 自定义函数案例演示 1. SparkSQL函数…

在nvidia jetson nx 板子上使用VPI+cuda backend计算光流

nvida的VPI可以调用CPU、GPU、PVA、VIC、NVENC、OFA等后端资源。因此恰当的使用vpi可以把部分需要gpu的计算让其他的计算资源来承担来降低cpu的负载&#xff0c;降低cpu过载造成设备卡死、计算异常等各种各样的风险。 下面介绍一下使用VPIcuda backend 计算LK稀疏光流。nvidia官…

Spark Streaming的核心功能及其示例PySpark代码

Spark Streaming是Apache Spark中用于实时流数据处理的模块。以下是一些常见功能的实用PySpark代码示例&#xff1a; 基础流处理&#xff1a;从TCP套接字读取数据并统计单词数量 from pyspark import SparkContext from pyspark.streaming import StreamingContext# 创建Spar…

windows蓝牙驱动开发-BLE音频(二)

详细设计 音频格式要求 音频帧持续时间 蓝牙 LE 音频配置文件允许实现支持音频帧持续时间为 7.5 毫秒或 10 毫秒的音频流式处理。 Windows 要求 IHV 提供的编解码器支持这两个帧持续时间&#xff0c;以确保与蓝牙 LE 音频配件设备的互操作性&#xff0c;并与连接到系统的其他…

【Rust的2种线程锁 阻塞 vs 挂起】

async_std::sync::Mutex 和 std::sync::Mutex 之间的主要区别在于它们如何处理线程阻塞和异步编程模型。以下是两者的关键差异&#xff1a; 标准库的 Mutex (std::sync::Mutex) 同步阻塞&#xff1a;当一个线程尝试获取 std::sync::Mutex 的锁时&#xff0c;如果锁已经被其他线…

数字化时代,传统代理模式的变革之路

在数字化飞速发展的今天&#xff0c;线上线下融合&#xff08;O2O&#xff09;成了商业领域的大趋势。这股潮流&#xff0c;正猛烈冲击着传统代理模式&#xff0c;给它带来了新的改变。 咱们先看看线上线下融合现在啥情况。线上渠道那是越来越多&#xff0c;企业纷纷在电商平台…