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

推荐订阅源

Y
Y Combinator Blog
The GitHub Blog
The GitHub Blog
Vercel News
Vercel News
D
DataBreaches.Net
MongoDB | Blog
MongoDB | Blog
H
Help Net Security
小众软件
小众软件
美团技术团队
T
The Blog of Author Tim Ferriss
爱范儿
爱范儿
D
Docker
Martin Fowler
Martin Fowler
大猫的无限游戏
大猫的无限游戏
博客园 - 聂微东
Blog — PlanetScale
Blog — PlanetScale
H
Hackread – Cybersecurity News, Data Breaches, AI and More
罗磊的独立博客
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
V2EX
S
SegmentFault 最新的问题
云风的 BLOG
云风的 BLOG
B
Blog
雷峰网
雷峰网
The Cloudflare Blog

博客园 - .Dove

报表 Share point 2010 报表配置 vs.Net2003无法打开或创建Web应用程序若干解决办法. (转) word在任务栏中的显示 时间比较 转(w3wp的内存占用不能及时释放) 远程主机强迫关闭了一个现有的连接 xpath问题 - .Dove - 博客园 Connect internal only, until freed. ContentBounds Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information." click once 存储过程 Shell 本人 http://blog.zhaoshang-sh.com/2006/router/archives/2006/683.html Server was unable to process request. ---> ORA-01000: 超出打开游标的最大数 Cache Server was unable to process request. ---> System.Data.OracleClient requires Oracle client software version 8.1.7 or greater.
UNION (转)
.Dove · 2006-03-16 · via 博客园 - .Dove

UNION 运算符是将两个或更多查询的结果组合为单个结果集

该结果集包含联合查询中的所有查询的全部行。这与使用联接组合两个表中的列不同。

使用 UNION 组合查询的结果集有两个最基本的规则:

1。所有查询中的列数和列的顺序必须相同。

2。数据类型必须兼容

a.UNION的结果集列名与第一个select语句中的结果集中的列名相同,其他select语句的结果集列名被忽略

b.默认情况下,UNION 运算符是从结果集中删除重复行。如果使用all关键字,那么结果集将包含所有行并且不删除重复行

c.sql是从左到右对包含UNION 运算符的语句进行取值,使用括号可以改变求值顺序

--例如:

select * from tablea

union all

(

select * from tableb

union all

select * from tablec

)

这样就可以先对tablebtablec合并,再合并tablea

d.如果要将合并后的结果集保存到一个新数据表中,那么into语句必须加入到第一条select

e.只可以在最后一条select语句中使用 order by compute 子句,这样影响到最终合并结果的排序和计数汇总

f.group by having 子句可以在单独一个select查询中使用,它们不影响最终结果

--例如:

select name as 姓名,class as 班级,grade as 年级

       into #students

       from stud87

       union all

select * from stud88

       union all

select * from stud89

       order by 年级

3个班级的合并结果(按grade排序)插入到临时表 #students里面