视图操作:

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 数据库的操作的更多相关文章

  1. php模拟数据库常用操作效果

    test.php <?php header("Content-type:text/html;charset='utf8'"); error_reporting(E_ALL); ...

  2. Android-Sqlite数据库的操作

    Sqlite数据库的简单操作: 设置增删改查的按钮,xml界面布局设置 <?xml version="1.0" encoding="utf-8"?> ...

  3. (四)SQL入门 数据库的操作与事务管理

    数据库的操作,有三个最基本的语句,insert插入,update修改,delete删除. 不同的数据库厂商的实现可能不同,所以就不说具体的语法怎么写的了.说语法也没有意义,到处都可以复制粘贴,记得听某 ...

  4. Laravel框架数据库CURD操作、连贯操作使用方法

    Laravel框架数据库CURD操作.连贯如何来操作了这个操作性是非常的方便简单了我们在这里来为各位介绍一篇相关的教程,具体的细节步骤如下文介绍.   Laravel是一套简洁.优雅的PHP Web开 ...

  5. zabbix数据库mariadb从服务器迁移到云mysql数据库的操作

    zabbix数据库mariadb从本机迁移到云mysql数据库的操作 1.将zabbix数据库导出,并导入到云数据库中 由于数据库较大,如果直接使用shell会话中断会导致数据库导出或者导入失败,使用 ...

  6. 使用my exclipse对数据库进行操作(4)

    四.删除 public class class4 { public static void main(String[] args) { // TODO Auto-generated method st ...

  7. 从C#到Objective-C,循序渐进学习苹果开发(7)--使用FMDB对Sqlite数据库进行操作

    本随笔系列主要介绍从一个Windows平台从事C#开发到Mac平台苹果开发的一系列感想和体验历程,本系列文章是在起步阶段逐步积累的,希望带给大家更好,更真实的转换历程体验.本篇主要开始介绍基于XCod ...

  8. MYSQL数据库的操作

    Mysql的连接方式: 1.原生函数:mysql_connect($server,$username,$password);   //打开一个到Mysql服务器的连接 mysql_select_db( ...

  9. DBA必备:MySQL数据库常用操作和技巧

    DBA必备:MySQL数据库常用操作和技巧 2011-02-25 15:31 kaduo it168 字号:T | T MySQL数据库可以说是DBA们最常见和常用的数据库之一,为了方便大家使用,老M ...

随机推荐

  1. 7-将本地的javaweb项目部署到Linux服务器的一般操作

    一.基本流程介绍: 1.安装tomcat;2.安装mysql;3.将本地的javaweb导出成.war文件,传到服务器的tomcat/webapps/下面4.将数据库文件导出成.sql文件,传到服务器 ...

  2. linux-redhat-git源码安装

    1.查看是否已安装git,如果存在自带的git,则卸载 查看git版本 $ git --version 删除自带git $ yum remove git 2.安装依赖包 $ yum -y instal ...

  3. div+css隐藏内容样式方法

    div css隐藏内容样式方法     div+css隐藏内容方法 一般情况下,css隐藏的用途,如下: 1.对文本的隐藏 2.隐藏超链接(另类黑链) 3.对统计代码隐藏 4.隐藏超出图片 5.css ...

  4. YAML教程

    一.简介 YAML是一种人们可以轻松阅读的数据序列化格式,并且它非常适合对动态编程语言中使用的数据类型进行编码.YAML是YAML Ain't Markup Language简写,和GNU(" ...

  5. Python.__getattr__Vs__getattribute__

    __getattr__ Vs __getattribute__ class Fish(object): def __getattr__(self, key): if key == 'color': p ...

  6. Javascript中escape()、encodeURI()、encodeURIComponent()的区别

    JavaScript中有三个可以对字符串编码的函数,分别是: escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,decod ...

  7. system v消息队列demo(未编译)

    #include <stdio.h> #include <string.h> #include <stdlib.h> #include <errno.h> ...

  8. fastjson解析List对象

    List<String[]> body = JSON.parseObject(msg.getBody().toString(), new TypeToken<List<Stri ...

  9. ubuntu系统中安装RoboMongo

    1.下载RoboMongo RoboMongo官网下载链接.选择好相应版本. 2.解压文件 tar -xzf robomongo--linux-x86_64-.tar.gzcd robomongo-0 ...

  10. angularjs写公共方法

    'use strict'; angular.module('fast-westone') .factory('commonUtilService', function () { return { /* ...