码迷,mamicode.com
首页 > 其他好文 > 详细

union 和 union all

时间:2015-10-25 00:56:26      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:

UNION 内部的 SELECT 语句必须拥有相同数量的列。列也必须拥有相似的数据类型。同时,每条 SELECT 语句中的列的顺序必须相同。


UNION ALL 命令和 UNION 命令几乎是等效的,不过 UNION ALL 命令会列出所有的值。意思就是相同字段有相同值,就会重复显示。

select prjcode,jgdm, count(1) from (
  (select prjcode,jgdm from d_file9_0001 where status=0 and attr=1 ) 
  union all
  (select prjcode,jgdm from d_file10_0001 where status=0 and attr=1 ) 
  union all
  (select prjcode,jgdm from d_file11_0001 where status=0 and attr=1 ) 
) t
group by prjcode,jgdm

 

union 和 union all

标签:

原文地址:http://www.cnblogs.com/chaoslane/p/4908092.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!