下订单超过4次的女顾客查询:
select c.customer_id, count(o.order_id) as orders_ct from oe.customers c join oe.orders o on c.customer_id = o.customer_id where c.gender = 'F' group by c.customer_id having count(o.order_id) > 4 order by orders_ct, c.customer_id
注意:group by子句
select 列表中的任何非聚合字段都必须包括在group by 表达式中 group by 还可以包含两个附加运算 ROLLUP和CUBE
标量子查询:在select中使用另外一个select 语句来产生结果中的一列值,这个查询只能返回一行一列的值,这种类型的查询称为标量子查询
例子:
select c.customer_id, c.cust_first_name||' '||c.cust_last_name, (select e.last_name from hr.employees e where e.employee_id = c.account_mgr_id) acct_mgr from oe.customers c;
子查询插入:
insert into scott.bonus (ename, job, sal) select ename, job, sal * .10 from scott.emp;
多表插入:
insert all --小于10000插入small_customers when sum_orders < 10000 then into small_customers --介于10000~100000插入medium_customers when sum_orders >= 10000 and sum_orders < 100000 then into medium_customers --大于100000插入 large_customers else into large_customers select customer_id, sum(order_total) sum_orders from oe.orders group by customer_id ;
update语句:
--创建表利用已有表的数据 create table employees2 as select * from hr.employees ; --添加主键 alter table employees2 add constraint emp2_emp_id_pk primary key (employee_id) ; --1.使用表达式更新一个单列的值 update employees2 set salary = salary * 1.10 -- increase salary by 10% where department_id = 90 ; --2.通过子查询更新一个单列的值 update hr.employees employees set salary = (select employees2.salary from employees2 where employees2.employee_id = employees.employee_id and employees.salary != employees2.salary) where department_id = 90 ; --3.通过在where子句中使用子查询确定要更新的单列的值 update hr.employees set salary = salary * 1.10 where department_id in (select department_id from departments where department_name = 'Executive') ; --4.通过select语句定义表及列的值来更新表 update (select e1.salary, e2.salary new_sal from hr.employees e1, employees2 e2 where e1.employee_id = e2.employee_id and e1.department_id = 90) set salary = new_sal; --5.通过子查询来更新多列 update hr.employees employees set (salary, commission_pct) = (select employees2.salary, .10 comm_pct from employees2 where employees2.employee_id = employees.employee_id and employees.salary != employees2.salary) where department_id = 90 ;
delete语句:
--1.通过where 字句筛选的条件进行删除 delete from employees2 where department_id = 90; --2.使用from子句的子查询删除 delete from (select * from employees2 where department_id = 90); --3.通过where 字句中的子查询来进行删除 delete from employees2 where department_id in (select department_id from hr.departments where department_name = 'Executive');
merge语句:同时完成了插入,更新,删除
merge into dept60_bonuses b using ( select employee_id, salary, department_id from hr.employees where department_id = 60) e on (b.employee_id = e.employee_id) when matched then update set b.bonus_amt = e.salary * 0.2 where b.bonus_amt = 0 delete where (e.salary > 7500) when not matched then insert (b.employee_id, b.bonus_amt) values (e.employee_id, e.salary * 0.1) where (e.salary < 7500);
相关推荐
第1讲:基础语法 内容介绍: 1.为什么学习oracle 2.介绍oracle及其公司的背景 3.学会安装、启动、卸载oracle 4.oracle开发工具 5.Sql*plus的常用命令 6.oracle用户管理 一、主流数据库包括: ?微软:sql server...
第一章 Oracle入门 一、 数据库概述 数据库(Database)是按照数据结构来组织、存储和管理数据的仓库,它产生于距今五十年前。简单来说是本身可视为电子化的文件柜——存储电子文件的处所,用户可以对文件中的数据...
由于标准SQL处理数据能力有局限,每种数据库产品在其基础之上又增加了第三代编程语言的特性,例如Oracle增加PL/SQL、 等DB2增加了SQL/PL、微软增加了T-SQL 3)数据完整性:指业务数据的正确性与完备性。包括...
010101_【第1章:JAVA概述及开发环境搭建】_JAVA发展概述笔记.pdf 010102_【第1章:JAVA概述及开发环境搭建】_Java开发环境搭建笔记.pdf 010201_【第2章:简单Java程序】_简单Java程序笔记.pdf 010301_【第3章:Java...
第一章 PL/SQL概述........................358 第二章 PL/SQL程序结构................359 第三章 PL/SQL数据类型................362 第四章 PL/SQL中的控制语句........368 第五章 PL/SQL游标......................
第一章 PL/SQL概述........................358 第二章 PL/SQL程序结构................359 第三章 PL/SQL数据类型................362 第四章 PL/SQL中的控制语句........368 第五章 PL/SQL游标......................
第一阶段教学内容安排(200课时) 课程名称 课程内容 培训目的 C# 基本语法、面向对象的思想、数据结构和算法以及设计模式(120课时) 详细介绍.Net Framework、C# 基本语法、编程规范和编程技巧、面向对象的认识...
\contentsline {chapter}{Contents}{2}{section*.1} {1}Java基础}{17}{chapter.1} {1.1}基本语法}{17}{section.1.1} {1.2}数字表达方式}{17}{section.1.2} {1.3}补码}{19}{section.1.3} {1.3.1}总结}{23}{...
Java常年占据热门编程语言排行榜第一,Java工程师综合就业排名第一,完成此路径能够应用SSM常用框架结合面向对象编程思想实现项目开发,完成Linux系统下的项目部署运行。将能胜任月薪8,000RMB--15,000RMB的职位,...
第一阶段教学内容安排(200课时) 课程名称 课程内容 培训目的 C# 基本语法、面向对象的思想、数据结构和算法以及设计模式(120课时) 详细介绍.Net Framework、C# 基本语法、编程规范和编程技巧、面向对象的认识...
第一阶段教学内容安排(200课时) 课程名称 课程内容 培训目的 C# 基本语法、面向对象的思想、数据结构和算法以及设计模式(120课时) 详细介绍.Net Framework、C# 基本语法、编程规范和编程技巧、面向对象的认识...
Essential .NET 读书笔记 [第一部分] NET FrameWork的Collections支持 .NET的反射在软件设计上的应用 关于跨程序集的反射 实现C#和VB.net之间的相互转换 深入剖析ASP.NET组件设计]一书第三章关于ASP.NET运行原理讲述...
<br>第一阶段教学内容安排(200课时) 课程名称 课程内容 培训目的 C# 基本语法、面向对象的思想、数据结构和算法以及设计模式(120课时) 详细介绍.Net Framework、C# 基本语法、编程规范和编程技巧、...
<br>第一阶段教学内容安排(200课时) 课程名称 课程内容 培训目的 C# 基本语法、面向对象的思想、数据结构和算法以及设计模式(120课时) 详细介绍.Net Framework、C# 基本语法、编程规范和编程技巧、...
12、系统软件分类 1、操作系统 windows 、linux、unix 等 2、编程软件 汇编语言、高级语言、机器语言、C语言、C++、java、C#等 3、数据库软件 SQL Server、Oracle、Mysql和Visual FoxPro等。 13、应用软件分类〔...
爱奇艺2021Java方向笔试题(第一场).docx 看透springMvc源代码分析与实践.pdf 网易2021招聘笔试- 系统开发研发工程师(提前批).docx 网易2021笔试- Java 开发工程师(提前批).docx 网易2021笔试- Java 开发工程师...
如果不一致就会出错,这一章主要在上一讲基于接口编程的基础上完成如下事情: 1. 用 mybatis 查询数据,包括列表 2. 用 mybatis 增加数据 3. 用 mybatis 更新数据. 4. 用 mybatis 删除数据. 查询数据,前面已经讲过...
1、一张表,里面有ID自增主键,当insert了17条记录之后,删除了第15,16,17条记录,再把Mysql重启,再insert一条记录,这条记录的ID是18还是15 ? 2、Mysql的技术特点是什么? Mysql数据库软件是一个客户端或服务器...