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

SQL¾­µä¶ÌС´úÂëÊÕ¼¯ 1

--
SQL Server£º
Select
 
TOP
 N 
*
 
from
 
TABLE
 
Order
 
By
 
NewID
() 
--
Access£º
Select
 
TOP
 N 
*
 
from
 
TABLE
 
Order
 
By
 Rnd(ID)  
Rnd(ID) ÆäÖеÄIDÊÇ×Ô¶¯±àºÅ×ֶΣ¬¿ÉÒÔÀûÓÃÆäËûÈκÎÊýÖµÀ´Íê³É£¬±ÈÈçÓÃÐÕÃû×Ö¶Î(UserName) 
Select
 
TOP
 N 
*
  
from
 
TABLE
 
Order
 
BY
 Rnd(
Len
(UserName)) 
--
MySql£º
Select
 
*
 
from
 
TABLE
 
Order
 
By
 
Rand
() Limit 
10
  
--
¿ªÍ·µ½NÌõ¼Ç¼
Select
 
Top
 N 
*
 
from
 ±í
--
Nµ½MÌõ¼Ç¼(ÒªÓÐÖ÷Ë÷ÒýID)
Select
 
Top
 M
-

*
 
from
 ±íWhere ID 
in
 (
Select
 
Top
 M ID 
from
 ±í) 
Order
 
by
 ID  
Desc
--
Ñ¡Ôñ10´Óµ½15µÄ¼Ç¼
select
 
top
 
5
 
*
 
from
 (
select
 
top
 
15
 
*
 
from
 
table
 
order
 
by
 id 
asc
) table_±ðÃûorder 
by
 id 
desc
 
--
Nµ½½áβ¼Ç¼
Select
 
Top
 N 
*
 
from
 ±íOrder 
by
 ID 
Desc
 
--
ÏÔʾ×îºó5Ìõ¼Ç¼,µ«ÊÇÏÔʾµÄ˳Ðò±ØÐëΪ5,6,7,8,9,10,¶ø²»ÊÇ10,9,8,7,6,5 ÈçϽâ¾ö·½·¨:
select

top

5

from
test
where
id
in
(
select

top

5

from
test
order

by
id
desc
)
order

by
id
asc

--
ͨ¹ýÕâ¸öÎÊÌâÒ²ÄÜ×ܽá³ö4-10Ìõ,5-100ÌõÕâÖÖÏÞ¶¨Ò»¶¨·¶Î§ÄÚµÄsqlÓï¾äµÄд·¨:
select

top

<
Ä©¶ËID
-
¶¥¶ËID
+
1
>

*

from

<
±íÃû
>

where
ID
not

in
(
select

top

<
¶¥¶ËID
-
1
>
) ID
from

<
±íÃû
>
)
--
ÀýÈç:4-10Ìõ¾ÍÓ¦¸Ãд³É
select

top

10
-
4
+
1

*

from
test
where
id


Ïà¹ØÎĵµ£º

SQLÓï¾äµÄÓÅ»¯

 SQLÓï¾ä¼¶±ðµÄÓÅ»¯ÊÇÎÒÃÇʵ¼Ê¹¤×÷ÖнӴ¥×î¶àµÄ£¬¼¸ºõËùÓеÄÊý¾Ý¿âÓ¦ÓÃ˵µ½µ×¶¼ÊÇSQLÓï¾äµÄ¾ßÌåÖ´ÐУ¬Òò´ËÈçºÎ¶ÔSQL½Å±¾±¾Éí½øÐÐÓÅ»¯£¬Ìá¸ßÖ´ÐÐЧÂʾÍÏÔµÃÓÈΪÖØÒª¡£ÒÔÏÂÊÇһЩͨÓõÄÉè¼ÆÔ­Ôò¡£
   (1)ʹÓÃselectÓï¾ä²éѯʱ£¬¾¡Á¿²»ÒªÊ¹ÓÃselect *¡¡Óï¾ä£¬¶øÊÇÓ¦¸ÃÖ¸Ã÷¾ßÌåÒª²éѯµÄ×ֶΣ¬ÌáÈ¡µÄ×Ö¶ÎÊýÁ¿Ô½É ......

SQL Server 2005/2008Êý¾Ý¿âÓʼþ

Æô¶¯Êý¾Ý¿âÓʼþ¹¦ÄÜ
 
sp_configure 'show advanced', 1;
GO
RECONFIGURE;
GO
sp_configure 'Database Mail XPs', 1;
GO
RECONFIGURE;
GO
 
 
 
 -- ÅäÖÃÊý¾Ý¿âÓʼþ
 -- Ìí¼ÓÓʼþÕË»§
execute msdb.dbo.sysmail_add_account_sp
    @account_name = 'ÓÊÏäÕ ......

ÓÃSQLÓï¾ä´´½¨±í&ÓÃSQLÓï¾ä´´½¨Êý¾Ý¿â

Êý¾Ý¿âÖеÄËùÓÐÊý¾Ý´æ´¢ÔÚ±íÖС£Êý¾Ý±í°üÀ¨ÐкÍÁС£Áоö¶¨Á˱íÖÐÊý¾ÝµÄÀàÐÍ¡£Ðаüº¬ÁËʵ¼ÊµÄÊý¾Ý¡£ 
ÀýÈ磬Êý¾Ý¿âpubsÖеıíauthorsÓоŸö×ֶΡ£ÆäÖеÄÒ»¸ö×Ö¶ÎÃûΪΪau_lname£¬Õâ¸ö×ֶα»ÓÃÀ´´æ´¢×÷ÕßµÄÃû×ÖÐÅÏ¢¡£Ã¿´ÎÏòÕâ¸ö±íÖÐÌí¼ÓÐÂ×÷Õßʱ£¬×÷ÕßÃû×־ͱ»Ìí¼Óµ½Õâ¸ö×ֶΣ¬²úÉúÒ»ÌõмǼ¡£ 
ͨ¹ý¶¨Òå×ֶ䪎 ......

¼Ç¼¼¸Ìõ¸Ð¾õ²»´íµÄsqlÓï¾ä

SELECT id,ip,from_unixtime(last_task_request_time) t1, from_unixtime(last_task_finish_time) t2
from yq_nodemanage
WHERE node_type=1
ORDER BY t1 DESC;
SELECT sum(unix_timestamp(gather_time)-unix_timestamp(publish_time))/(count(*)*60) from yq_bbs_docinfo
WHERE unix_timestamp(publish_time)>un ......

SQL Server·ÖÒ³3ÖÖ·½°¸

 SQL Server·ÖÒ³3ÖÖ·½°¸±ÈÆ´
´ËתÔØÔ´×ÔÀîºé¸ùµÄblog.×÷ÕßÊÇ΢ÈíµÄMVP!Ï£Íû´ó¼Ò²Î¿¼ÒÔÏÂ3ÖÖ·½°¸,°´Êµ¼ÊÇé¿öÑ¡Ôñ!
½¨Á¢±í£º
CREATE TABLE [TestTable] (
 [ID] [int] IDENTITY (1, 1) NOT NULL ,
 [FirstName] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
 [LastName] [nvarchar] (100) ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ