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

SQL³£Ó÷ÖÒ³µÄ°ì·¨

SQL³£Ó÷ÖÒ³µÄ°ì·¨:
±íÖÐÖ÷¼ü±ØÐëΪ±êʶÁУ¬[ID] int IDENTITY (1,1)
1.·ÖÒ³·½°¸Ò»£º(ÀûÓÃNot InºÍSELECT TOP·ÖÒ³)
Óï¾äÐÎʽ£º 
SELECT TOP Ò³¼Ç¼ÊýÁ¿ *
from ±íÃû
WHERE (ID NOT IN
  (SELECT TOP (ÿҳÐÐÊý*(Ò³Êý-1)) ID
  from ±íÃû
  ORDER BY ID))
  ORDER BY ID
//×Ô¼º»¹¿ÉÒÔ¼ÓÉÏһЩ²éѯÌõ¼þ
Àý:
select top 2 *
from Sys_Material_Type
where (MT_ID not in
    (select top (2*(3-1)) MT_ID from Sys_Material_Type  order by MT_ID))
order by MT_ID
2.·ÖÒ³·½°¸¶þ£º(ÀûÓÃID´óÓÚ¶àÉÙºÍSELECT TOP·ÖÒ³£©
Óï¾äÐÎʽ£º
SELECT TOP ÿҳ¼Ç¼ÊýÁ¿ *
from ±íÃû
WHERE (ID >
          (SELECT MAX(id)
    from (SELECT TOP ÿҳÐÐÊý*Ò³Êý id  from ±í
          ORDER BY id) AS T)
      )
ORDER BY ID
Àý:
SELECT TOP 2 *
from Sys_Material_Type
WHERE (MT_ID >
          (SELECT MAX(MT_ID)
          from (SELECT TOP (2*(3-1)) MT_ID
                from Sys_Material_Type
                ORDER BY MT_ID) AS T))
ORDER BY MT_ID
3.·ÖÒ³·½°¸Èý£º(ÀûÓÃSQLµÄÓαê´æ´¢¹ý³Ì·ÖÒ³)
create  procedure SqlPager
@sqlstr nvarchar(4000), --²éѯ×Ö·û´®
@currentpage int, --µÚNÒ³
@pagesize int --ÿҳÐÐÊý
as
set nocount on
declare @P1 int, --P1ÊÇÓαêµÄid
@rowcount int
exec sp_cursoropen @P1 output,@sqlstr,@scrollopt=1,@ccopt=1, @rowcount=@rowcount output
select ceiling(1.0*@rowcount/@pagesize) as ×ÜÒ³Êý--,@rowcount as ×ÜÐÐÊý,@currentpage as µ±Ç°Ò³
set @currentpage=(@currentpage-1)*@pagesize+1
exec sp_cursorfetch @P1,16,@currentpage,@pagesize
exec sp_cursorclose @P1
set nocount off
4.×ܽá:
ÆäËüµÄ·½°¸£ºÈç¹ûûÓÐÖ÷¼ü£¬¿ÉÒÔÓÃÁÙʱ±í£¬Ò²¿ÉÒÔÓ÷½°¸Èý×ö£¬µ«ÊÇЧÂÊ»áµÍ¡£
½¨ÒéÓÅ»¯µÄʱºò£¬¼ÓÉÏÖ÷¼üºÍË÷Òý£¬²éѯЧÂÊ»áÌá¸ß¡£
ͨ¹ýSQL ²éѯ·ÖÎöÆ÷£¬ÏÔʾ±È½Ï£ºÎҵĽáÂÛÊÇ:
·ÖÒ³·½°¸¶þ£º(ÀûÓÃID´óÓÚ¶àÉÙºÍSELECT


Ïà¹ØÎĵµ£º

Ëæ»úÑ¡ÔñÐеÄSQLÓï¾ä? ORACLE SQLSERVER ECT.

MySQL:
SELECT column from table
ORDER BY RAND()
LIMIT 1
PostgreSQL:
SELECT column from table
ORDER BY RANDOM()
LIMIT 1
Microsoft SQL Server:
SELECT TOP 1 column from table
ORDER BY NEWID()
IBM DB2
SELECT column, RAND() as IDX
from table
ORDER BY IDX FETCH FIRST 1 ROWS ONLY
Thanks Ti ......

ÈýÖÖSQL·ÖÒ³·¨¡¾×ªÌû¡¿

Ó¦Ò»¸öÅóÓѵÄÒªÇó£¬ÌùÉÏÊղصÄSQL³£Ó÷ÖÒ³µÄ°ì·¨¡«¡«

±íÖÐÖ÷¼ü±ØÐëΪ±êʶÁУ¬[ID] int IDENTITY (1,1)

1.·ÖÒ³·½°¸Ò»£º(ÀûÓÃNot InºÍSELECT TOP·ÖÒ³)

Óï¾äÐÎʽ£º 
SELECT TOP Ò³¼Ç¼ÊýÁ¿ *
from ±íÃû
WHERE (ID NOT IN
  (SELECT TOP (ÿҳÐÐÊý*(Ò³Êý-1)) ID
  from ± ......

ÈÃSQL SERVERÍ»ÆÆ2GÄÚ´æÏÞÖÆ


32
λµÄ²Ù×÷ϵͳֻÄÜÓÃ
4G
µÄÄڴ棨²»È·¶¨Õâ¾ä»°ÊÇ·ñÕýÈ·£©£¬ÒòΪ
2
µÄ
32
´Î·½ÊÇ
4G
¡£Ä¬ÈϵÄÇé¿öÏ£¬²Ù×÷ϵͳ¸ø×Ô¼ºÁôÁË
2G
£¬Ê£ÏµÄ
2G
¸øÓ¦ÓóÌÐò¡£ËùÒÔ£¬Ã¿¸öÓ¦ÓóÌÐòËùÄÜʹÓõÄÄڴ棬×î´ó²»³¬¹ý
2G
¡£¾Ý˵¿ÉÒÔ¸Ä
WINDOWS
µÄ
BOOT.INI
£¬Ç¿ÖƲÙ×÷ϵͳֻʹÓÃ
1G
£¬¼´Ê¹ÕâÑù£¬Ó¦ÓóÌÐòÒ²ÖÁ¶àÊÇ ......

5±¾¾­µäSQLµç×ÓÊé


SQL±¦µä

SQL±ØÖª±Ø»áµÚÈý°æ

SQLÈëÞ­µäµÚËÄ°æ

Sams Teach Yourself SQL in 10 Minutes Third Edition

SQL The Complete Reference

......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ