惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cloudbric
Cloudbric
Y
Y Combinator Blog
N
Netflix TechBlog - Medium
D
DataBreaches.Net
Microsoft Azure Blog
Microsoft Azure Blog
Recorded Future
Recorded Future
Martin Fowler
Martin Fowler
M
MIT News - Artificial intelligence
U
Unit 42
爱范儿
爱范儿
F
Full Disclosure
Google Online Security Blog
Google Online Security Blog
腾讯CDC
小众软件
小众软件
A
Arctic Wolf
云风的 BLOG
云风的 BLOG
Webroot Blog
Webroot Blog
B
Blog RSS Feed
Project Zero
Project Zero
Hacker News - Newest:
Hacker News - Newest: "LLM"
博客园 - 聂微东
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
C
CXSECURITY Database RSS Feed - CXSecurity.com
SecWiki News
SecWiki News
S
Schneier on Security
Recent Commits to openclaw:main
Recent Commits to openclaw:main
H
Help Net Security
W
WeLiveSecurity
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
WordPress大学
WordPress大学
MongoDB | Blog
MongoDB | Blog
G
Google Developers Blog
雷峰网
雷峰网
C
Cybersecurity and Infrastructure Security Agency CISA
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
I
Intezer
V
V2EX
宝玉的分享
宝玉的分享
H
Hacker News: Front Page
aimingoo的专栏
aimingoo的专栏
L
LangChain Blog
C
Check Point Blog
O
OpenAI News
博客园 - Franky
大猫的无限游戏
大猫的无限游戏
C
CERT Recently Published Vulnerability Notes
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
K
Kaspersky official blog
Stack Overflow Blog
Stack Overflow Blog
Know Your Adversary
Know Your Adversary

博客园 - 电电儿

FME Cloud 账号申请流程 FME中通过HTMLExtractor向HTML要数据 在windows 2003下安装 django + apache + mod_python arcgis中坐标系统的简单描述 arcgis 中利用txt坐标文件创建要素的办法,含txt文件详细格式~ Django静态文件配置备忘录 【转】ARCSDE+ORACLE备份 测量坐标系中单个多边形面积解析法计算的程序源代码 - 电电儿 - 博客园 System.Data.SQLite测试 oracle左右连接的另外表示方法 Oracle 函数大全(字符串函数,数学函数,日期函数,逻辑运算函数,其他函数) Oracle中的Union、Union All、Intersect、Minus inner join,full outer join,left join,right join,cross join Oracle中的自连接(self join) Oracle 中的natural join (自然连接) ORACLE JOIN 用正则表达式分析正则表达式!求正则表达式组数~ - 电电儿 - 博客园 BoooLee pyretoolkit -- 一个基于python re模块的在线正则表达式测试工具 GDAL 在windows python环境下的安装步骤
测试oracle with as
电电儿 · 2009-09-15 · via 博客园 - 电电儿

为了简化SQL语句,可以将语句分成若干个视图来操作,但是创建的试图将会作为对象保存在数据库中,但经常有一些语句只是临时使用,所以在sql-99规范中有了with as 语句,该语句实质上就是创建临时视图,来帮助你简化语句并使语句结构更清晰更容易阅读。

下面的测试中会用到3张表,courseresults(课程-学生-成绩表)、courses(课程表)、students(学生表),先给出建表语句:

create table COURSERESULTS
(
  CID   NUMBER,
  SID   NUMBER,
  SCORE FLOAT not null
)

create table COURSES
(
  CID     NUMBER not null,
  CNAME   VARCHAR2(100) not null,
  TID     NUMBER,
  CREDITS NUMBER not null
)

create table STUDENTS
(
  SID       NUMBER not null,
  SNAME     VARCHAR2(50) not null,
  SEX       CHAR(1),
  BIRTHDATE DATE,
  EMAIL     VARCHAR2(50)
)

例1:获取student表全部数据

with s as

(select * from students)

select * from s;

例2:获取小于平均成绩的学生学号和成绩

with c as
(select avg(score) as value from courseresults)
select sid,score from courseresults,c where score>c.value;

例3:获取课程平均成绩大于85分的男生的学号

with
s1 as
(select sid from courseresults group by sid having avg(score)>85),
s2 as
(select sid from students where sex='m')
select * from s1 intersect select * from s2;

结论:使用with as语句的确可以使复杂的SQL语句具有更清晰的结构。