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

推荐订阅源

P
Proofpoint News Feed
V
V2EX
WordPress大学
WordPress大学
Google DeepMind News
Google DeepMind News
Martin Fowler
Martin Fowler
小众软件
小众软件
Blog — PlanetScale
Blog — PlanetScale
月光博客
月光博客
The Cloudflare Blog
T
Tailwind CSS Blog
H
Help Net Security
腾讯CDC
爱范儿
爱范儿
人人都是产品经理
人人都是产品经理
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The GitHub Blog
The GitHub Blog
Microsoft Security Blog
Microsoft Security Blog
Stack Overflow Blog
Stack Overflow Blog
D
DataBreaches.Net
C
Check Point Blog
量子位
酷 壳 – CoolShell
酷 壳 – CoolShell
美团技术团队
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com

博客园 - .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里面