Day44 数据库的操作
视图操作:
1.左连接查询
select * from person left join dept on person.dept_id = dept.did
2. 右连接
3. 内连接 inner join
4. UNION ALL 全连接
=======================
一 、 多表操作
select * from person,dept
二 、多表联合操作
select * from person,dept where person.dept_id =dept.did
select * from person,dept where person.dept_id =dept.did and person.salary >3000
三、多表连接查询
左连接查询 (以左表作为基准)
select *from person left JOIN dept on person.dept_id = dept.did
内连接查询
select * from person inner JOIN dept where person.dept_id =dept.did
4.全连接查询 full JOIN
select * from person LEFT JOIN dept ON person.dept_id = dept.did
UNION ALL
select * from person RIGHT JOIN dept on person.dept_id = dept.did;
二 、 复杂的多表查询 。
1. 查询出 教学部 年龄大于20岁,并且工资小于40000的员工,按工资倒序排列.(要求:分别使用多表联合查询和内连接查询)
select * from person inner join dept on person.dept_id = dept.did and dept.dname = '教学部' and person.age >20 and salary <40000 order by person.salary asc
2.查询每个部门中最高工资和最低工资是多少,显示部门名称
select dept.dname , MAX(salary),MIN(salary) from person LEFT JOIN dept on person.dept_id =dept.did group by person.dept_id
2.求最大工资那个人的姓名和薪水
1.求最大工资
select max(salary) from person;
2.求最大工资那个人叫什么
select name,salary from person where salary=53000; 合并
select name,salary from person where salary=(select max(salary) from person);
3. 求工资高于所有人员平均工资的人
1.求平均工资
select avg(salary) from person; 2.工资大于平均工资的 人的姓名、工资
select name,salary from person where salary > 21298.625; 合并
select name,salary from person where salary >(select avg(salary) from person);

Day44 数据库的操作的更多相关文章
- php模拟数据库常用操作效果
test.php <?php header("Content-type:text/html;charset='utf8'"); error_reporting(E_ALL); ...
- Android-Sqlite数据库的操作
Sqlite数据库的简单操作: 设置增删改查的按钮,xml界面布局设置 <?xml version="1.0" encoding="utf-8"?> ...
- (四)SQL入门 数据库的操作与事务管理
数据库的操作,有三个最基本的语句,insert插入,update修改,delete删除. 不同的数据库厂商的实现可能不同,所以就不说具体的语法怎么写的了.说语法也没有意义,到处都可以复制粘贴,记得听某 ...
- Laravel框架数据库CURD操作、连贯操作使用方法
Laravel框架数据库CURD操作.连贯如何来操作了这个操作性是非常的方便简单了我们在这里来为各位介绍一篇相关的教程,具体的细节步骤如下文介绍. Laravel是一套简洁.优雅的PHP Web开 ...
- zabbix数据库mariadb从服务器迁移到云mysql数据库的操作
zabbix数据库mariadb从本机迁移到云mysql数据库的操作 1.将zabbix数据库导出,并导入到云数据库中 由于数据库较大,如果直接使用shell会话中断会导致数据库导出或者导入失败,使用 ...
- 使用my exclipse对数据库进行操作(4)
四.删除 public class class4 { public static void main(String[] args) { // TODO Auto-generated method st ...
- 从C#到Objective-C,循序渐进学习苹果开发(7)--使用FMDB对Sqlite数据库进行操作
本随笔系列主要介绍从一个Windows平台从事C#开发到Mac平台苹果开发的一系列感想和体验历程,本系列文章是在起步阶段逐步积累的,希望带给大家更好,更真实的转换历程体验.本篇主要开始介绍基于XCod ...
- MYSQL数据库的操作
Mysql的连接方式: 1.原生函数:mysql_connect($server,$username,$password); //打开一个到Mysql服务器的连接 mysql_select_db( ...
- DBA必备:MySQL数据库常用操作和技巧
DBA必备:MySQL数据库常用操作和技巧 2011-02-25 15:31 kaduo it168 字号:T | T MySQL数据库可以说是DBA们最常见和常用的数据库之一,为了方便大家使用,老M ...
随机推荐
- 18-从n个数中选m个
#include <iostream>using namespace std; int f(int n, int m){ if(n < m) //这个条 ...
- java里的静态成员变量是放在了堆内存还是栈内存
转自http://bbs.csdn.NET/topics/370001490 堆区: 1.存储的全部是对象,每个对象都包含一个与之对应的class的信息.(class的目的是得到操作指令) 2.jvm ...
- dede后台一片空白
原因是你修改了后台的数据库连接信息文件data/common.inc.php,保存的后文件编码并不是utf-8,而是变成了ANSI或utf-8 + bom的. 解决方法: 用editplus或note ...
- uploadify 文件上传报http 302错误
uploadify文件上传会报http 302错误,在配置文件中将处理上传的通用类取消验证, 假设上传的通用处理类是fileUpload.ashx,则在配置文件同添加下面过滤配置能解决问题. < ...
- Java的8种包装类:Wrapper Class
Java有8种基本数据类型,为什么又要出现对应的8种包装类: 1.Java的8种基本数据类型不支持面向对象编程机制 2.8种基本数据类型不具备“对象”的特性:没有成员变量.方法可供调用 3.例如:某个 ...
- Zookeeper 系列(四)ZKClient API
Zookeeper 系列(四)ZKClient API 环境准备: <dependency> <groupId>com.101tec</groupId> <a ...
- 使用delphi 开发多层应用(二十四)KbmMW 的消息方式和创建WIB节点
KbmMW 中支持基于UDP的消息广播,也支持TCP/IP hub/spoke 方式,还有 基于UDP或者TCP/IP 的点对点的消息传输. 1.基于UDP的消息广播
- 2018.07.25 bzoj3878: [Ahoi2014&Jsoi2014]奇怪的计算器(线段树)
传送门 线段树综合. 让我想起一道叫做siano" role="presentation" style="position: relative;"&g ...
- 【转】Paxos算法3-实现探讨
——转自:{老码农的专栏} 前两篇Paxos算法的讨论,让我们对paxos算法的理论形成过程有了大概的了解,但距离其成为一个可执行的算法程序还有很长的路要走,原因是很多的细节和错误未被考虑.Googl ...
- C++之类和对象课后习题1
建立一个对象数组,内放5个学生的(学号,成绩),设立一个函数max,用指向对象的指针作函数参数,在max函数中找出5个学生的最高成绩者,并输出其学号. #include<iostream> ...