Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

SQLµÄ·ÖÒ³²éѯ

·ÖÒ³²éѯµÄÔ­Àí£º
 Õâ¸öÖ»ÄÜÓÃÔÙSql2005¼°ÒÔÉϵİ汾
DECLARE @pagenum AS INT, @pagesize AS INT  
SET @pagenum = 2   
SET @pagesize = 3   
SELECT *   
from (SELECT ROW_NUMBER() OVER(ORDER BY score DESC, speaker) AS rownum,    
        speaker, track, score   
      from SpeakerStats) AS D   
WHERE rownum BETWEEN (@pagenum-1)*@pagesize+1 AND @pagenum*@pagesize  
Õâ¸öÊÊÓÃÖ§³ÖtopµÄsql
SELECT TOP (10) * from hy_hotel_info   
 WHERE hi_id >(SELECT MAX (hi_id)    
from (select top £¨2*10£© hi_id    
from hy_hotel_info order by hi_id) as talTMP ) order by hi_id   
Ò»¸ö·ÖÒ³²éѯµÄ´æ´¢¹ý³Ì
/****** ¶ÔÏó: StoredProcedure [dbo].[SP_Pagination] ½Å±¾ÈÕÆÚ: 05/05/2010 15:02:13 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[SP_Pagination]
@tblName varchar(255), -- ±íÃû .
@strGetFields varchar(1000) ='* ', -- ÐèÒª·µ»ØµÄÁÐ
@fldName varchar(255)= ' ', -- ÅÅÐòµÄ×Ö¶ÎÃû
@PageSize int = 10, -- Ò³³ß´ç
@PageIndex int = 1, -- Ò³Âë
@doCount bit = 0, -- ·µ»Ø¼Ç¼×ÜÊý,·Ç 0 ÖµÔò·µ»Ø
@OrderType int = 0, -- ÉèÖÃÅÅÐòÀàÐÍ,·Ç 0 ÖµÔò½µÐò
@strWhere varchar(1500) =' ' , -- ²éѯÌõ¼þ(×¢Òâ: ²»Òª¼Ówhere)
@keyDate varchar(1500) =' '
AS
declare @strSQL varchar(5000) -- Ö÷Óï¾ä
declare @strTmp varchar(110) -- ÁÙʱ±äÁ¿
declare @strOrder varchar(400) -- ÅÅÐòÀàÐÍ
declare @fldNames varchar(100) -- ÅÅÐò×ֶΣ¬Èç¹ûÁ½Õűí,Ö»²éÑ


Ïà¹ØÎĵµ£º

sqlÖÐand¼°or µÄÖ´ÐÐЧÂÊ

Ó¦ÓÃÖз¢ÏÖsqlÖеÄand¼°orµÄÖ´ÐÐЧÂÊÎÊÌâ
£ó£ñ£ìÓï¾ä£¬ÎªÊ²Ã´°Ñ×îºóµÄ£ï£ò»»³É£á£î£ä£¬²éѯµÄ¾ÍºÜ¿ì£¬Ê¹ÓõÄÊÇmssql·¶ÀýÖÐnorthwindÊý¾Ý¿âΪÀý£¬
select * from Orders a left join [Order Details] b on a.orderid = b.orderid
where a.customerid like '%ics%' or b.productid in (42,72)
×·×ÙÁËÓï¾äµÄÖ´Ðз½°¸,·¢ÏÖ ......

SQLµÄ×óÁ¬½Ó£¨left join £©


SELECT g.rid, room_no, planed_count,cc from
    (SELECT rid,room_no, planed_count from YC_HOTEL_ROOM_T ) r
left join
    (SELECT rid,count(*) cc  from  YC_GUEST_INFO_T group by rid ) g
ON   r.rid = g.rid  WHERE planed_ ......

SQL¸ß¼¶Ó¦Óà Garin Zhang

×·¼Ó£ºrow_number, rank, dese_rank, ntile
1. row_number: Ϊ²éѯ³öÀ´µÄÿһÐмǼÉú³ÉÒ»¸öÐòºÅ¡£
SELECT row_number() OVER(ORDER BY field) AS row_n
from tablename;
·ÖÒ³²éѯ£º
with t_towtable
as (select row_number over(order by field1) as row_number from tb)
select * from t_rowtable where row_numbe ......

SQL server µÚÈýƪ ¶à±íÁª½Ó²éѯ

        ¶à±íÁª½Ó²éѯ
Ò»¡¢¶à±íÁª½Ó²éѯµÄ·ÖÀà
¶à±íÁª½Ó²éѯʵ¼ÊÉÏÊÇͨ¹ý¸÷¸ö±íÖ®¼ä¹²Í¬ÁеĹØÁªÐÔÀ´²éѯÊý¾ÝµÄ£¬ËüÊǹØϵÊý¾Ý¿â²éѯ×îÖ÷ÒªµÄÌØÕ÷¡£
Áª½Ó²éѯ¿É·ÖΪÈý´óÀ࣬·ÖÁíΪ£º
1£®  ÄÚÁª½Ó¡£
2£®  ÍâÁª½Ó¡£
3£®  ½»²æÁª½Ó¡£
ÄÇôÎÒÃÇÒ»ÆðÀ´¿´Ò»ÏÂÈçºÎʹÓö ......

oracle sql tuning

alert index mem_ct monitoring usage;
desc v$object_usage;
set linesize 190
select * from v$object_usage;
SQL>SET AUTOTRACE ON;
¡¡¡¡*autotrace¹¦ÄÜÖ»ÄÜÔÚSQL*PLUSÀïʹÓÃ
¡¡¡¡ÆäËûһЩʹÓ÷½·¨£º
¡¡¡¡2.2.1¡¢ÔÚSQLPLUSÖеõ½Óï¾ä×ܵÄÖ´ÐÐʱ¼ä
¡¡¡¡SQL> set timing on;
2.2.2¡¢Ö»ÏÔʾִÐмƻ®--(»áÍ¬Ê ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ