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

高手帮帮忙
现在我有两段代码
代码一如下:
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排序的那种!谢谢各位高手拉!

------解决方案--------------------
你将你上面的查询的结果看成一个表,第一个表看成A(用括号括起来,后面加A就可以),第二个表看成B
然后用这个语句实现。
select * from A inner join B on A.shopid = B.shopid