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

  1. 对数据分组的总结

在这里插入图片描述
举例:统计各个部门的平均工资,并且是大于1000的,并且按照平均工资从高到底排序

mysql> select avg(stsal) as myavgsal, stdepno from staff group by stdepno having myavgsal > 1000 order by myavgsal desc;
+-------------+---------+
| myavgsal    | stdepno |
+-------------+---------+
| 7000.200000 |      10 |
| 5350.200000 |      30 |
| 3094.766667 |      20 |
+-------------+---------+
  1. 笛卡尔积的原理
    在这里插入图片描述
    多表查询练习:
  2. 显示员工名,工资,及所在部门的名字
select staff.stname , staff.stsal, department.dname from staff, department where department.deptno = staff.stdepno;
  1. 显示部门号为10的部门名,员工名,工资,
select staff.stname , staff.stsal, department.dname from staff, department where department.deptno = staff.stdepno and department.deptno = 10;
  1. 显示每个员工的姓名,工资, 及其工资的级别
select staff.stname, staff.stsal, salalevel.slevel from staff, salalevel where staff.stsal >= slower and staff.stsal <= shig;
  1. 显示每个员工姓名,工资,以及部门名,以及工资级别
    这样就设计到三张表的关联查询,三张表为了避免笛卡尔积, 就需要至少两个查询条件
select staff.stname, staff.stsal , department.dname, salalevel.slevel from staff,department,salalevel where staff.stdepno = department.deptno and staff.stsal >= salalevel.slower and staff.stsal <= salalevel.shig;

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

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

相关文章

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

转 wiki https://zh.wikipedia.org/zh-cn/公开密钥加密 公开密钥密码学 &#xff08;英语&#xff1a;Public-key cryptography&#xff09;&#xff0c;也称为非对称式密码学&#xff08;英语&#xff1a;asymmetric cryptography&#xff09;&#xff0c;是密码学的一种算…

mysql 学习笔记 多表查询02

把一张表 想象成两张表&#xff0c;进行多表查询 举例&#xff1a; 查询 所有员工的 姓名 以及 其 上级姓名 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安装&#xff08;mac&#xff09; brew install redis 如果需要后台运行 redis 服务&#xff0c;使用命令 brew services start redis 如果不需要后台服务&#xff0c;则使用命令 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

centos 无法连接网络

最小化安装&#xff0c;没有ifconfig默认没法联网 cd /etc/sysconfig/network-scripts/ sudo vi ifcfg-en33 也有可能是其他后缀 找到ONBOOTno service network restart 然后yum install net-tools