select top 5 * from shelf
where Sortid=377
and Sortid=463
and Sortid=438
and Sortid=646
order by sortid
where Sortid=377
and Sortid=463
and Sortid=438
and Sortid=646
order by sortid
解决方案 »
- 求助,SQL多行查一行
- 在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许
- 求《SQL 2000决策分析: OLAP建置与应用》随书光盘
- SQL请教,这里人气旺
- 各位高手,join語句怎麼實現不了我的意思?
- 哪位能给我一个sqlserver的下载地址?谢谢
- 大家都来看看
- 修改SQL Server 2000的sa密码时密码中包含{},密码修改成功后用sa不可再登录
- 怎么把一张FOXPRO的表(*.dbf)导入到SQLServer中?
- 帮帮忙,给分。
- 如何得到刚插入记录的ID(自动产生的)?
- 我只乘下最后一分,很简单的存储过程,如何构造动态的sql语句
肯定比
Select * from TableName要快,具体快多少,不能一概而定的。
回复人: changechange(http://access911.net 是我的个人网站,欢迎光临) ( ) 信誉:378
不是给你一个参考页面吗?
http://access911.net/fixhtm/72FAB31E10DCEEF3.htm
我看了一下,收获不小,按照你说的sortid,我按照参考页面说的表结构,并加多了一个sort id
--888.如下
create table #t (aid int identity(2,1),a_desc varchar(10))insert into #t values('11')
insert into #t values('22')
select ident_current('#t')
select @@identityselect ident_incr('#t')
select ident_seed('#t')create table #tt (id varchar(10),rid varchar(10))insert into #tt values('001','377')
insert into #tt values('002','377')
insert into #tt values('003','377')
insert into #tt values('011','377')
insert into #tt values('012','377')
insert into #tt values('013','377')
insert into #tt values('004','463')
insert into #tt values('014','463')
insert into #tt values('015','463')
insert into #tt values('016','463')
insert into #tt values('005','463')
insert into #tt values('006','463')
insert into #tt values('007','438')
insert into #tt values('008','438')
insert into #tt values('017','438')
insert into #tt values('018','438')
insert into #tt values('019','438')
insert into #tt values('009','646')
insert into #tt values('010','646')
insert into #tt values('020','646')
insert into #tt values('021','646')
insert into #tt values('022','646')
insert into #tt values('023','646')
insert into #tt values('024','646')
insert into #tt values('025','888')
insert into #tt values('026','888')
insert into #tt values('027','888')
select * from #tt
/*
id rid
---------- ----------
001 377
002 377
003 377
011 377
012 377
013 377
004 463
014 463
015 463
016 463
005 463
006 463
007 438
008 438
017 438
018 438
019 438
009 646
010 646
020 646
021 646
022 646
023 646
024 646
025 888
026 888
027 888(27 row(s) affected)
*/select *
from #tt as a
--where id in(select top 5 id from #tt where rid=a.rid order by id)
where exists (select top 1 id from (select top 5 id from #tt where rid=a.rid order by id) b
where b.id = a.id)
and a.rid in('377','463','438','646')--这句或许你不需要,你可能也是按照sortid取出各自的前5笔,按照参考页面的回答人说的where id in(select top 5 id from #tt where rid=a.rid order by id),数据量大的时候,很慢,如果转化为exists会快点,具体快多少,那与很多因素有关,不过同样的环境就是比in要快得多,后面加的and a.rid in('377','463','438','646')--速度不慢,因为直接比较不需要去表中整个搜索,速度也会加分,感谢changechange提供的东西,好像也到了好多东西~