日期:2014-05-18 浏览次数:22368 次
select q.Id,q.Title from ( select q.Id,q.Title,ROW_NUMBER() over(order by q.PostTime desc) as row from Question q inner join Answer a on q.BestAnswerId=a.Id ) a where row between 1 and 5
select Id,Title from (select q.Id,q.Title,ROW_NUMBER() over(order by q.PostTime desc) as row from Question q inner join Answer a on q.BestAnswerId=a.Id ) a where row between 1 and 5
select q.Id,q.Title from ( select q.Id,q.Title,ROW_NUMBER() over(order by q.PostTime desc) as row from Question q inner join Answer a on q.BestAnswerId=a.Id ) a --这里起的别名是 q,上方select 用的是q where row between 1 and 5
------解决方案--------------------
作为外表的a表,没有必要用q.id,q表是内表,你在外面也访问不到得。
------解决方案--------------------
子查询在里面能用外面的别名。但不能在外面用子查询里面的别名
例
select * from tb1 a where not exists (select * from tb2 b join b.id=a.id)--子查询在里面能用外面的别名。 select * from a on a.id=b.id