你要的是这样? 内容 时间 分类 dd 1990-1-8 1 aa 1990-2-1 1 cc 1990-2-3 2 ee 1990-2-5 2
create table #t (nr varchar(10),rq varchar(10),type varchar(1)) insert into #t values('dd', '1990-1-8', '1') insert into #t values('aa', '1990-2-1', '1') insert into #t values('bb', '1990-2-2', '1') insert into #t values('gg', '1990-3-21', '1') insert into #t values('cc', '1990-2-3', '2') insert into #t values('ee', '1990-2-5', '2') insert into #t values('ff', '1990-2-8', '2')select * from #t t where (select count(1) from #t where type=t.type and rq<=t.rq)<=2结果: dd 1990-1-8 1 aa 1990-2-1 1 cc 1990-2-3 2 ee 1990-2-5 2
请lw1a2解释一下用count(1)是什么意思?
count(1)就是任意行的数量。 比如,select 1 from Table1,那么行数就是count(1)
lw1a2(一刀 知我者谓我心忧,不知我者谓我何求) 大哥,能解释一下你那语句吗? select * from #t t where (select count(1) from #t where type=t.type and rq<=t.rq)<=2 实在太强了,有点难理解,谢谢.....
count(1)就是任意行的数量。select count(1) from #t where type=t.type and rq<=t.rq 那整句怎么解释?
我想选择“分类”中的前两组,就是如果表还有其他数据,我把所有排在前面的两组type提取出来,应该怎么办?
内容 时间 分类
dd 1990-1-8 1
aa 1990-2-1 1
cc 1990-2-3 2
ee 1990-2-5 2
insert into #t values('dd', '1990-1-8', '1')
insert into #t values('aa', '1990-2-1', '1')
insert into #t values('bb', '1990-2-2', '1')
insert into #t values('gg', '1990-3-21', '1')
insert into #t values('cc', '1990-2-3', '2')
insert into #t values('ee', '1990-2-5', '2')
insert into #t values('ff', '1990-2-8', '2')select *
from #t t
where (select count(1) from #t where type=t.type and rq<=t.rq)<=2结果:
dd 1990-1-8 1
aa 1990-2-1 1
cc 1990-2-3 2
ee 1990-2-5 2
比如,select 1 from Table1,那么行数就是count(1)
select *
from #t t
where (select count(1) from #t where type=t.type and rq<=t.rq)<=2
实在太强了,有点难理解,谢谢.....
那整句怎么解释?