mysql 学习笔记13 查询语句强化

  1. 使用控制语句计算员工年工资
    在这里插入图片描述
  2. 查询入职时间,晚于1982年1月1日的,(日期是可以进行比较的)
    在这里插入图片描述
  3. where中like的使用
    在这里插入图片描述
select name, sal from users where like 'S%';
select name, sal from users where like '__O%';
  1. order by,使用多个字段进行排序
    按照部门号升序而雇员工资降序排列
    在这里插入图片描述

order by 使用别名进行排序
在这里插入图片描述
5. 分页查询
查询要求:
在这里插入图片描述
举例:
limit 0,3
0表示其实位置,3表示需要多少条记录
在这里插入图片描述
-------统计函数的相关使用-------
6. 显示工资最高员工的名字,以及工作岗位:
在这里插入图片描述
7. 显示工资高于平均工资的员工的信息:
在这里插入图片描述
8. 显示平均公司低于2000的部门号和他的平均工资在这里插入图片描述
9. 显示各部门的平均工资和最高工资
在这里插入图片描述
10. 显示每个部门的每种岗位的平均工资和最低工资

mysql> select avg(stsal), min(stsal), stjob, stdepno from staff group by stdepno, stjob;
+--------------+------------+-------+---------+
| avg(stsal)   | min(stsal) | stjob | stdepno |
+--------------+------------+-------+---------+
| 10000.200000 |   10000.20 | 丞相     |      10 |
|  9000.200000 |    9000.20 | 军师     |      10 |
|  2000.200000 |    2000.20 | 文员     |      10 |
|  5000.200000 |    5000.20 | 前锋     |      20 |
|  2713.680000 |    2000.20 | 将军      |      20 |
|   500.200000 |     500.20 | 太监     |      30 |
|   900.200000 |     900.20 | 皇妃      |      30 |
| 10000.200000 |   10000.20 | 皇帝     |      30 |
+--------------+------------+-------+---------+
  1. 统计所有雇员的平均工资,总计工资,最高工资和最低工资
mysql> select avg(stsal), sum(stsal), max(stsal), min(stsal) from staff;
+-------------+------------+------------+------------+
| avg(stsal)  | sum(stsal) | max(stsal) | min(stsal) |
+-------------+------------+------------+------------+
| 4690.000000 |   60970.00 |   10000.20 |     500.20 |
+-------------+------------+------------+------------+
  1. 统计每种岗位的雇员总数,平均工资
mysql> select avg(stsal), stjob, count(*) from staff group by stjob;
+--------------+-------+----------+
| avg(stsal)   | stjob | count(*) |
+--------------+-------+----------+
| 10000.200000 | 丞相     |        1 |
|  9000.200000 | 军师     |        1 |
|  5000.200000 | 前锋     |        1 |
|   500.200000 | 太监     |        1 |
|  2713.680000 | 将军      |        5 |
|  2000.200000 | 文员     |        1 |
|   900.200000 | 皇妃      |        1 |
| 10000.200000 | 皇帝     |        2 |
+--------------+-------+----------+
  1. 统计员工总数,和 补助高于500的员工数
mysql> select count(stname), count( if(stcom>=500, stcom, null)) from staff;
+---------------+-------------------------------------+
| count(stname) | count( if(stcom>=500, stcom, null)) |
+---------------+-------------------------------------+
|            13 |                                   8 |
+---------------+-------------------------------------+
  1. 统计管理者的人数
mysql> select count(distinct(stmgr)) from staff;
+------------------------+
| count(distinct(stmgr)) |
+------------------------+
|                      3 |
+------------------------+

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/382465.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

mysql学习笔记14 多表查询初步

对数据分组的总结 举例:统计各个部门的平均工资,并且是大于1000的,并且按照平均工资从高到底排序 mysql> select avg(stsal) as myavgsal, stdepno from staff group by stdepno having myavgsal > 1000 order by myavgsal desc; ----…

SSH加密密码中的非对称式密码学

转 wiki https://zh.wikipedia.org/zh-cn/公开密钥加密 公开密钥密码学 (英语:Public-key cryptography),也称为非对称式密码学(英语:asymmetric cryptography),是密码学的一种算…

mysql 学习笔记 多表查询02

把一张表 想象成两张表,进行多表查询 举例: 查询 所有员工的 姓名 以及 其 上级姓名 select s1.stname, s2.stname from staff as s1, staff as s2 where s1.stmgr s2.stid;查询 员工李岩的 上级姓名 select s1.stname, s2.stname from staff as s1…

Mac Redis安装入门教程

redis安装(mac) brew install redis 如果需要后台运行 redis 服务,使用命令 brew services start redis 如果不需要后台服务,则使用命令 redis-server /usr/local/etc/redis.conf 启动redis服务 执行以下命令 /usr/local/bin…

Shell 脚本基础学习

查询手册 菜鸟教程 for循环和seq的使用 echo "method 1" for i in seq 1 10; doecho $i; doneecho "method 2" for i in {1..10} doecho $i; doneecho "method 3" for i in seq 1 2 10; doecho $i; done进入目录创建文件重定向内容 cd Test …

mysql 学习笔记15 子查询

子查询定义&#xff1a; 单上子查询举例&#xff1a; 显示与 员工 关平 同一部门的员工&#xff0c; 但不包括关平 select * from staff where staff.stdepno (select staff.stdepno from staff where stname关平) and staff.stname<> 关平 ;多行子查询举例&#xff…

shell自学笔记

文章目录重定向数值比较逻辑操作符使用范围关于文件判断测试表达式test [] [[]] (())的区别sed教程AWK教程重定向 0表示标准输入 1表示标准输出 2表示标准错误输出 默认为标准输出重定向&#xff0c;与 1> 相同 2>&1 意思是把 标准错误输出 重定向到 标准输出. &…

ffmpeg简单使用小记

1. 使用ffmpeg 进行普通切片&#xff08;ts&#xff09;操作 .\ffmpeg.exe -i a.mp4 -y -f hls -c copy -hls_time 10 .\s.m3u82. 使用ffmpeg 对视频进行设置旋转参数为0 .\ffmpeg.exe -i a.mp4 -metadata:s:v:0 rotate0 -c copy outputfile.mp43. 使用文件对视频进行加密 .\…

python3安装教程配置配置阿里云

配置全新阿里云 Linux iz2ze0ajic0vbvwnjhw2bwz 3.10.0-693.2.2.el7.x86_64 #1 SMP Tue Sep 12 22:26:13 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux 安装依赖包 wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1rc1.tar.xz 新建一个文件夹存放python3 mkdir /u…

python 使用requests模块进行 视频文件的下载

公司项目需要下载一批视频文件&#xff0c; 格式是mp4和mkv的&#xff0c;就借助request模块进行了下载&#xff0c;前提是源服务器返回文件的大小&#xff0c;以及可以接受 请求头headers中带有Range参数 以下是下载逻辑&#xff1a; resp requests.head(urlreal_video_url)…

Git的多人协作和分支处理测试

首先配置ssh密钥 克隆项目 配置两台主机&#xff08;一台本地mac&#xff0c;一台云服务器&#xff09;通过这样的方式模拟多人开发。 创建分支 [root ~/Git_test_多人协作和冲突合并/branch_test]$ ls README.md [root ~/Git_test_多人协作和冲突合并/branch_test]$ git b…

python 碎片整理 threading模块小计

threading模块中&#xff0c; start()与run()方法的区别 threading.start() 方法是开启一个线程 threading.run() 方法则是普通的函数调用

git教程目录

git入门教程 PyCharm和git安装教程 Git的多人协作和分支处理测试

msyql 禁止远程访问

1. use mysql 2. select host , user from user; 查看用户 与 对应的host 3. 将 host 中是 %的改为 localhost&#xff0c; 酌情也可以其他用户 的host限制为localhost update user set host "localhost" where user "root" and host "%" 4. …

mysql索引回表

先索引扫描&#xff0c;再通过ID去取索引中未能提供的数据&#xff0c;即为回表。 建表 mysql> create table T( id int primary key, k int not null, name varchar(16), index (k))engineInnoDB;如果语句是 select * from T where ID500&#xff0c;即主键查询方式&am…

C++ 执行cmd命令 并获取输出

这是参考别人的 &#xff0c;具体来源忘了&#xff0c;唉&#xff0c;等想起来一定补上出处 头文件 PipeCmd.h #ifndef _PIPE_CMD_H_ #define _PIPE_CMD_H_#include <Windows.h>// 执行 cmd 命令, 并获取执行结果数据 BOOL PipeCmd(char *pszCmd, char *pszResultBuffe…

iterm2 保存阿里云登陆并防止断开连接

commando edit profiles新增一个页面 添加命令 ssh -A -p 22 -o ServerAliveInterval60 rootIP

QString中包含中文的时候, 转为char *

转载自 https://blog.csdn.net/mihang2/article/details/39026865 QString中包含中文的时候&#xff0c; 转为char * void FileEncWidget::QString2ANSI(QString text, char **pOut) {std::wstring wIn text.toStdWString();char *pcstr (char *)malloc(sizeof(char)*(2 * w…

brew安装

官网&#xff1a;http://brew.sh/ 安装软件&#xff1a;brew install 软件名&#xff0c;例&#xff1a;brew install wget搜索软件&#xff1a;brew search 软件名&#xff0c;例&#xff1a;brew search wget卸载软件&#xff1a;brew uninstall 软件名&#xff0c;例&#…

关于异步IO模型的学习

看到两篇不错的文章&#xff0c;转载了&#xff1a; https://www.cnblogs.com/fanzhidongyzby/p/4098546.html https://www.cnblogs.com/aspirant/p/9166944.html