日期:2014-05-18  浏览次数:20439 次

高手进来帮帮忙!问个两个结果集链接的问题?
现在我有两段代码
代码一如下:
select   max(shop.[name])   as   shopname,max(shop.shopid)   as   shopid,count(*)   as   provide,sum(case   when   ifprint= '1 '   then   1   else   0   end)   as   ifprint,sum(case   when   ifprint= '0 '   then   1   else   0   end)   as   cancelprint   from   ticketinfo   with(index(IX_ticketinfo)),shop   where   ticketinfo.shopid=shop.shopid   and   ticketinfo.providedate> '2007-03-27   00:00:00 '   and   ticketinfo.providedate < '2007-03-27   23:59:59 '   group   by   ticketinfo.shopid   order   by   ifprint   DESC

代码二如下:
select  
max(shop.shopid)   as   shopid,
count(*)   as   rcvcount
from   paylist_bak   with(index(IX_paylist_bak)),shop  
where   paylist_bak.shopid=shop.shopid  
and   paylist_bak.rcvdate> '2007-03-26   00:00:00 '  
and   paylist_bak.rcvdate < '2007-03-26   23:59:59 '  
group   by   paylist_bak.shopid

我想两个结果合在一个结果集里面
paylist_bak.shopid是等于ticketinfo.shopid的
上次有个朋友告诉我用union   all联接两个结果,不过滤重复行
可是不是我需要的     我想代码一中的ticketinfo的shopid和代码二中的paylist_bak的shopid是可以等于     那应该可是生成一个结果集吧     改成一段代码最好       后边可以使用order   by排序的那种!谢谢各位高手拉!

------解决方案--------------------
--合并重复行
select * from A
union
select * from B

--不合并重复行
select * from A
union all
select * from B


--排序
select *
from
(
select * from A
union all
select * from B
) T
order by 字段名
------解决方案--------------------
两个结果集用行号进行关联。