首页 > 其他 > 详细

union 和 union all

时间:2015-10-25 00:54:25      阅读:176      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!