谁帮解释一下这个SQL是什么意思 SELECT NewsID,CategoryID,CreateTime FROM Public_News a WHERE ( SELECT count(*) FROM Public_News b WHERE b.CategoryID=a.CategoryID AND b.newsID>a.newsID )<5 order by CategoryID,CreateTime desc 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 declare @Public_News table (NewsID int,CategoryID int,CreateTime datetime)insert into @Public_Newsselect 1,2,'2009-02-12' union allselect 2,17,'2009-02-12' union allselect 3,15,'2009-02-12' union allselect 4,1,'2009-02-12' union allselect 5,7,'2009-02-12' union allselect 6,6,'2009-02-12' union allselect 7,5,'2009-02-12' union allselect 8,4,'2009-02-12' union allselect 9,1,'2009-02-12' union allselect 10,2,'2009-02-12' union allselect 11,2,'2009-02-12' union allselect 12,2,'2009-02-12' union allselect 13,2,'2009-02-12' union allselect 14,2,'2009-02-12' union allselect 15,2,'2009-02-12' union allselect 15,2,'2009-02-12' union allselect 15,2,'2009-02-12' union allselect 15,2,'2009-02-12' union allselect 15,2,'2009-02-12' union allselect 15,2,'2009-02-12' union allselect 16,3,'2009-02-12' union allselect 16,3,'2009-02-12' union allselect 16,2,'2009-02-12'select * from @Public_News/*NewsID CategoryID CreateTime----------- ----------- -----------------------1 2 2009-02-12 00:00:00.0002 17 2009-02-12 00:00:00.0003 15 2009-02-12 00:00:00.0004 1 2009-02-12 00:00:00.0005 7 2009-02-12 00:00:00.0006 6 2009-02-12 00:00:00.0007 5 2009-02-12 00:00:00.0008 4 2009-02-12 00:00:00.0009 1 2009-02-12 00:00:00.00010 2 2009-02-12 00:00:00.00011 2 2009-02-12 00:00:00.00012 2 2009-02-12 00:00:00.00013 2 2009-02-12 00:00:00.00014 2 2009-02-12 00:00:00.00015 2 2009-02-12 00:00:00.00015 2 2009-02-12 00:00:00.00015 2 2009-02-12 00:00:00.00015 2 2009-02-12 00:00:00.00015 2 2009-02-12 00:00:00.00015 2 2009-02-12 00:00:00.00016 3 2009-02-12 00:00:00.00016 3 2009-02-12 00:00:00.00016 2 2009-02-12 00:00:00.000(23 row(s) affected)*/SELECT NewsID,CategoryID,CreateTime FROM @Public_News a WHERE ( SELECT count(*) FROM @Public_News b WHERE b.CategoryID=a.CategoryID AND b.newsID>a.newsID )<5 order by CategoryID,CreateTime desc/*NewsID CategoryID CreateTime----------- ----------- -----------------------9 1 2009-02-12 00:00:00.0004 1 2009-02-12 00:00:00.00016 2 2009-02-12 00:00:00.00015 2 2009-02-12 00:00:00.00015 2 2009-02-12 00:00:00.00015 2 2009-02-12 00:00:00.00015 2 2009-02-12 00:00:00.00015 2 2009-02-12 00:00:00.00015 2 2009-02-12 00:00:00.00016 3 2009-02-12 00:00:00.00016 3 2009-02-12 00:00:00.0008 4 2009-02-12 00:00:00.0007 5 2009-02-12 00:00:00.0006 6 2009-02-12 00:00:00.0005 7 2009-02-12 00:00:00.0003 15 2009-02-12 00:00:00.0002 17 2009-02-12 00:00:00.000(17 row(s) affected)*/ 求一简单存储过程 帮忙看看哪里错了 SQL Sever新手求助~~~这句表格该怎么写? sql 2000里怎么让某个字段设置好后能能自增1 一个关于IP查询的SQL语句 SQL两个表数据查询,头有点晕 菜鸟虚心学习:如何在存储过程中读取二进制字段的数据? 插入中文字符显示???的问题 oracle数据库重构(主机名发生变化) SQL2012安装提示安装程序无法通过windows update服务搜索更新 关于SQL2005的问题 SQL MAIL
declare @Public_News table (NewsID int,CategoryID int,CreateTime datetime)
insert into @Public_News
select 1,2,'2009-02-12' union all
select 2,17,'2009-02-12' union all
select 3,15,'2009-02-12' union all
select 4,1,'2009-02-12' union all
select 5,7,'2009-02-12' union all
select 6,6,'2009-02-12' union all
select 7,5,'2009-02-12' union all
select 8,4,'2009-02-12' union all
select 9,1,'2009-02-12' union all
select 10,2,'2009-02-12' union all
select 11,2,'2009-02-12' union all
select 12,2,'2009-02-12' union all
select 13,2,'2009-02-12' union all
select 14,2,'2009-02-12' union all
select 15,2,'2009-02-12' union all
select 15,2,'2009-02-12' union all
select 15,2,'2009-02-12' union all
select 15,2,'2009-02-12' union all
select 15,2,'2009-02-12' union all
select 15,2,'2009-02-12' union all
select 16,3,'2009-02-12' union all
select 16,3,'2009-02-12' union all
select 16,2,'2009-02-12'select * from @Public_News/*
NewsID CategoryID CreateTime
----------- ----------- -----------------------
1 2 2009-02-12 00:00:00.000
2 17 2009-02-12 00:00:00.000
3 15 2009-02-12 00:00:00.000
4 1 2009-02-12 00:00:00.000
5 7 2009-02-12 00:00:00.000
6 6 2009-02-12 00:00:00.000
7 5 2009-02-12 00:00:00.000
8 4 2009-02-12 00:00:00.000
9 1 2009-02-12 00:00:00.000
10 2 2009-02-12 00:00:00.000
11 2 2009-02-12 00:00:00.000
12 2 2009-02-12 00:00:00.000
13 2 2009-02-12 00:00:00.000
14 2 2009-02-12 00:00:00.000
15 2 2009-02-12 00:00:00.000
15 2 2009-02-12 00:00:00.000
15 2 2009-02-12 00:00:00.000
15 2 2009-02-12 00:00:00.000
15 2 2009-02-12 00:00:00.000
15 2 2009-02-12 00:00:00.000
16 3 2009-02-12 00:00:00.000
16 3 2009-02-12 00:00:00.000
16 2 2009-02-12 00:00:00.000(23 row(s) affected)
*/
SELECT NewsID,CategoryID,CreateTime
FROM @Public_News a
WHERE (
SELECT count(*) FROM @Public_News b WHERE b.CategoryID=a.CategoryID AND
b.newsID>a.newsID )<5
order by CategoryID,CreateTime desc/*
NewsID CategoryID CreateTime
----------- ----------- -----------------------
9 1 2009-02-12 00:00:00.000
4 1 2009-02-12 00:00:00.000
16 2 2009-02-12 00:00:00.000
15 2 2009-02-12 00:00:00.000
15 2 2009-02-12 00:00:00.000
15 2 2009-02-12 00:00:00.000
15 2 2009-02-12 00:00:00.000
15 2 2009-02-12 00:00:00.000
15 2 2009-02-12 00:00:00.000
16 3 2009-02-12 00:00:00.000
16 3 2009-02-12 00:00:00.000
8 4 2009-02-12 00:00:00.000
7 5 2009-02-12 00:00:00.000
6 6 2009-02-12 00:00:00.000
5 7 2009-02-12 00:00:00.000
3 15 2009-02-12 00:00:00.000
2 17 2009-02-12 00:00:00.000(17 row(s) affected)
*/