博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

union查询,排序

Posted on 2011-01-27 15:10  一刻  阅读(159)  评论(0编辑  收藏  举报

declare @mytable table
(
  productId int,
  bigClassId int,
  aField int
)
 insert into @mytable
select top 10 productid,bigClassid,count(id)+sum(supportNum) as aField from tbcomments
group by productid,bigclassid order by aField desc
(select t.name,p.aField from tbTravel_Info t,@mytable as p where t.id=p.productid
union
select i.name,p.aField from tbAccident_Info i,@mytable as p where i.id=p.productid )
order by afield