日期:2014-05-17  浏览次数:20714 次

排序请教!
select * from 主题 where ID in (SELECT top 10 pid  FROM dbo.用户记录 where 点击=1 group by pid  order by COUNT(pid) desc)  

 有人知道怎样使外层和里层排序一致??现在就是外层获取不了COUNT(pid)

------解决方案--------------------
SELECT  A.*
FROM    主题 A
        INNER JOIN ( SELECT TOP 10
                            pid ,
                            COUNT(pid) AS num
                     FROM   用户记录
                     WHERE  点击 = 1
                     GROUP BY pid
                     ORDER BY COUNT(pid) DESC
                   ) B ON A.id = b.pid
ORDER BY B.num

------解决方案--------------------
try this,

select top 10 b.*
 from dbo.用户记录 a
 inner join 主题 b on a.pid=b.ID
 where a.点击=1 
 group by a.pid  
 order by count(a.pid) desc

------解决方案--------------------
顶楼上。