SQL Select N to M Records (single Table)
È¡±íÀïnµ½mÌõ¼Í¼µÄ¼¸ÖÖ·½·¨:
1. Ö»ÐèÒª²éѯǰMÌõÊý¾Ý(0 to M),
1.1 ʹÓà top(M) ·½·¨:
select top(3) * from [tablename]
1.2 ʹÓà set rowcount ·½·¨:
http://msdn.microsoft.com/zh-cn/library/ms188774(SQL.90).aspx
set rowcount M
select * from [tablename]
set rowcount 0
ȨÏÞ ÒªÇó¾ßÓÐ public ½ÇÉ«³ÉÔ±×ʸñ¡£
ÒªÖ´ÐÐset rowcount 0, ·ñÔòÓ°ÏìÒÔºó²éѯµÈ.
2.²éѯNµ½MÌõÊý¾Ý(N to M),
2.1 ±íÀïÃæÓбêʶÁÐ
2.1.1
select top (M-N+1) * from [tablename] where [columnname] not in (select top (N) [columnname] from [tablename])
2.1.2 ÄæÐòÏÔʾ
select top N * from (select top M * from [tablename] order by [columnname]) temp order by [columnname] desc
2.1.3 ˳ÐòÏÔʾ
select * from (select top N * from (select top M * from [tablename] order by [columnname]) temp1 order by [columnname] desc) temp2 order by [columnname]
2.2 ±íÀïÓÐidentityÊôÐÔ
select * from [tablename] where identitycol between N and M
Èç[columnname]ΪidentityÊôÐÔ,Ôò¿ÉÒÔд³É:
select * from [tablename] where [columnname] between N and M
2.3 ±íÀïÃæÓбêʶÁÐ, ÀûÓÃÁÙʱ±í
IF Exists(Select 1 from sysObjects Where Name ='temptable' And Type In ('temptable','U'))
begin
drop table [temptable]
end
select top M * into [temptable] from [tablename] order by [columnname]
set rowcount N
select * from [temptable] order by [columnname] desc
set rowcount 0
drop table [temptable]
2.4 Èç¹ûtablenameÀïûÓÐÆäËûidentityÁУ¬ÄÇô£º
exec sp_dboption [DataBaseName] ,'select into/bulkcopy',true
IF Exists(Select 1 from sysObjects Where Name ='temptable' And Type In ('temptable','U'))
begin
drop table temptable
end
select identity(int) id0,* into [temptable] from [tablename]
select * from temp where id0 >= N and id0 <= M
drop table temptable
Èç¹ûÄãÔÚÖ´ÐÐselect identity(int) id0,* into [temp
Ïà¹ØÎĵµ£º
×î½ü,Òò¸öÈ˵çÄÔÓ²ÅÌËð»µ,йºÈëÁË500GµÄ´óÓ²ÅÌ,°²×°ÁËwindows7,ÔÚwin7Éϰ²×°Á˶à¸öÐéÄâxp»ú,ÐéÄâ»úÓëʵ¼ÊµÄ»úÆ÷(Ö÷»ú)×é³ÉÁËÒ»¸ö¾ÖÓòÍø,ʵÏÖÔÚÐéÄâ»úÖÐͨ¹ýÔ¶³ÌÁ¬½ÓÖ÷»úµÄsql server.ÏÖ½«ÎÒµÄÊÔÑé¹ý³Ì½éÉÜÈçÏÂ,¹©ÓÐÐËȤ³¢ÊԵĴóÏÀ²Î¿¼.
1. °²×°ÐéÄâ»ú»·¾³.
ÏȰ²×°window7.0Æì½¢°æ (רҵÓëÆóÒµ°æÒ²¿ ......
´Ó¹ÙÍøÏÂÔØSQL Server 2008µÄ180ÌìÊÔÓðæÆäʵÓëÕýʽ°æÄÚÈÝÊÇ»ù±¾ÏàͬµÄ£¬Î¨Ò»µÄÇø±ð¾ÍÔÚÓÚ°²×°ÅäÖÃÎļþÖÐËù°üº¬µÄkey¡£¸÷ÖÖ°æ±¾µÄSQL ServerÔÚ½øÐе½ÕâÒ»²½Ö®Ç°¶¼ÊÇÍêȫһÑùµÄ£º
Microsoft® SQL Server® 2008 Enterprise Evaluation£º¿ª·¢ÈËÔ±ÊÔÓÃÌåÑé
Microsoft® SQL Server® 2008 Enterprise Evaluatio ......
½¨Á¢±í£º
CREATE TABLE [TestTable] (
[ID] [int] IDENTITY (1, 1) NOT NULL ,
[FirstName] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
[LastName] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
[Country] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[Note] [ ......
sql group by Ó÷¨
2009-07-16 11:01:00 Òµ½ç | ÆÀÂÛ(0) | ä¯ÀÀ(1676)
group byÖ÷ÒªÊÇÓÃÀ´·Ö×éµÄ£¬Ôõô¸ö·Ö×éÄØ£¿
ÒÔÏÂÓÃÁ½¸öÀý×Ó˵Ã÷Á½¸öʹÓ÷½Ã棬1ÊǺÏÀíµÄ·µ»ØºÏ¼ÆÖµ£¨·ÀÖ¹µÑ¿¨¶û»ýÏÖÏ󣩣¬2ÊÇÓ÷Ö×éÀ´ÕÒ³öÖØ¸´µÄ¼Ç¼
============================================================== ......
²»´íµÄ×ÊÁÏ,ת¹ýÀ´,·½±ãÈÕºó²é¿´Ê¹ÓÃ!!!
--¼à¿ØË÷ÒýÊÇ·ñʹÓÃ
alter index &index_name monitoring usage;
alter index &index_name nomonitoring usage;
select * from v$object_usage where index_name =
&index_name;
--ÇóÊý¾ÝÎļþµÄI/O·Ö²¼
select
df.name,phyrds,phywrts,phyblkrd,phyblkwrt,sin ......