日期:2014-05-18 浏览次数:20533 次
select a.* from ( select c_name,n_name from class,news where class.c_id = news.c_id ) a where n_name in (select top 20 n_name from ( select c_name,n_name from class,news where class.c_id = news.c_id ) b where c_name=a.c_name ) order by a.c_name,a.n_name
------解决方案--------------------
--每個類別下的20條?
select a.C_name,b.n_name from class a,news b
where a.c_id=b.c_id
and b.n_id in (select top 20 n_id from news where c_id=a.c_id order by n_id desc)
order by a.c_name,b.n_id desc
------解决方案--------------------
select n_id, n_name, C_name from (select * from news N where (select count(1) from news where c_id=N.c_id and n_id>N.n_id)<20) News join class on News.c_id=class.c_id order by N.c_id,N.n_id desc