Day36 数据库的操作
视图操作:

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);
Day36 数据库的操作的更多相关文章
- day36 数据库表操作 数据类型 完整性约束
今日内容 1.存储引擎表类型 2.数据类型 3.完整性约束 1.存储引擎表类型 指令: 1.show engines:#查看MySQL所有的引擎, 2.show variables like &quo ...
- 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( ...
随机推荐
- 安装gcc
yum -y install gcc yum -y install gcc-c++ yum install make -- 或者 yum groupinstall "Developmen ...
- python的条件判断
条件判断 计算机之所以能做很多自动化的任务,因为它可以自己做条件判断. 比如,输入用户年龄,根据年龄打印不同的内容,在Python程序中,用if语句实现: age = 20 if age >= ...
- MVC无刷新上传图片并显示
@{ ViewBag.Title = "Home Page"; } <script src="../../Scripts/swfobject.js" ty ...
- 2019-02-25 EST 科技文翻译
The Definition of Theme and Rheme The point of departure is equally presented to the speaker and to ...
- 解决You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order (order_name, customer)
在学习hibernate一对多映射关系时,根据视频学习的时候,例子是顾客和订单的问题,一个顾客有多个订单.按照视频中的敲代码出现了You have an error in your SQL synta ...
- global $GLOBALS 区别
PHP代码 复制代码 代码如下: <?php // 例子1 function test_global() { global $var1, $var2; $var2 =& $var1; } ...
- python day17面向对象-组合
组合: 给一个类的对象封装一个属性,这个属性是另一个类的对象. class GameRole: def __init__(self, name, ad, hp): self.name = name s ...
- HDU 4704 Sum(隔板原理+组合数求和公式+费马小定理+快速幂)
题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=4704 Problem Description Sample Input 2 Sample Outp ...
- RESTful Service API 常见问题解决方案
REST 风格的优秀设计应该像下面这些: - GET /users 获取所有用户 - GET /users/1234 获取ID为1234的用户 - POST /users 创建一个新用户 - PUT ...
- Fatal error: Call to undefined function mb_strlen()
php配置的时候出现:Fatal error: Call to undefined function mb_strlen() 表示php不能加载mbstring模块,在php 的配置文件php.in ...

