union (all)_SQL SERVER数据库_黑客防线网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN

union (all)

作者:黑客防线网安SQL维护基地 来源:黑客防线网安SQL维护基地 浏览次数:0

本篇关键词:selectfromwhereunion
黑客防线网安网讯:利用union 将多个select 的结果结合起来.union命令将来自不同select命令所生成的数据混合在一起,并将重复的数据删除仅留下一条,也就是数学上的并集关系。 如果你想让重复的数据也留下时,...

利用union 将多个select 的结果结合起来.union命令将来自不同select命令所生成的数据混合在一起并将重复的数据删除仅留下一条也就是数学上的并集关系
如果你想让重复的数据也留下时,可以使用union all取代原来的union命令

1.select prod_id ,sup_id
from sale_item
where order_no=10001
union
select prod_id,sup_id
from purchase
where pur_no=50001
order by 1,2
2.在sqlserver方面可以用case实现的,但在access里,只能用iif或union
select a.rmpwr,a.buypwr,yd-case when b.dl>0 then a.yd+b.rmpwr-b.bdl

##www.aspxuexi.com##
else a.yd-b.yd end
from (select mid,rmpwr,buypwr,(buypwr-rmpwr)as yd from main where month(dt)=2)a,(select mid,rmpwr,buypwr,(buypwr-rmpwr)as yd,bdl from main where month(dt)=1 b where a.mid=b.mid
在本机数据库中a,b同上
select a.ydl+b.rmpwr-b.ydl as yd from a,b where a.mid=b.mid and b.bdl>0
union all
select a.yd-b.yd from a,b where a.mid=b.mid and isnull(b.bdl,-1)<=0


 

    黑客防线网安服务器维护方案本篇连接:http://www.rongsen.com.cn/show-10463-1.html
网站维护教程更新时间:2012-03-21 03:04:41  【打印此页】  【关闭
我要申请本站N点 | 黑客防线官网 |  
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479

footer  footer  footer  footer