SQL·ÖÒ³Óï¾ä
ÓйطÖÒ³ SQL µÄ×ÊÁϺܶ࣬ÓеÄʹÓô洢¹ý³Ì£¬ÓеÄʹÓÃÓαꡣ±¾È˲»Ï²»¶Ê¹ÓÃÓα꣬ÎÒ¾õµÃËüºÄ×Ê¡¢Ð§Âʵͣ»Ê¹Óô洢¹ý³ÌÊǸö²»´íµÄÑ¡Ôñ£¬ÒòΪ´æ´¢¹ý³ÌÊǾ¹ýÔ¤±àÒëµÄ£¬Ö´ÐÐЧÂʸߣ¬Ò²¸üÁé»î¡£ÏÈ¿´¿´µ¥Ìõ SQL Óï¾äµÄ·ÖÒ³ SQL °É¡£
·½·¨1£º
ÊÊÓÃÓÚ SQL Server 2000/2005
SELECT TOP Ò³´óС *
from table1
WHERE id NOT IN
(
SELECT TOP Ò³´óС*(Ò³Êý-1) id from table1 ORDER BY id
)
ORDER BY id
·½·¨2£º
ÊÊÓÃÓÚ SQL Server 2000/2005
SELECT TOP Ò³´óС *
from table1
WHERE id >
(
SELECT ISNULL(MAX(id),0)
from
(
SELECT TOP Ò³´óС*(Ò³Êý-1) id from table1 ORDER BY id
) A
)
ORDER BY id
·½·¨3£º
ÊÊÓÃÓÚ SQL Server 2005
SELECT TOP Ò³´óС *
from
(
SELECT ROW_NUMBER() OVER (ORDER BY id) AS RowNumber,* from table1
) A
WHERE RowNumber > Ò³´óС*(Ò³Êý-1)
Ïà¹ØÎĵµ£º
1.×Ö·û´®º¯Êý
³¤¶ÈÓë·ÖÎöÓÃ
datalength(Char_expr) ·µ»Ø×Ö·û´®°üº¬×Ö·ûÊý,µ«²»°üº¬ºóÃæµÄ¿Õ¸ñ
substring(expression,start,length) ²»¶à˵ÁË,È¡×Ó´®
right(char_expr,int_expr) ·µ»Ø×Ö·û´®ÓÒ±ßint_expr¸ö×Ö·û
×Ö·û²Ù×÷Àà
upper(char_expr) תΪ´óд
lower(char_expr) תΪСд
space(int_expr) Éú³Éint_expr¸ö¿Õ¸ñ ......
ÕâÖÖÓ÷¨ÏàÐÅÔÚÍøÕ¾Öо³£Ê¹Óã¬ÈçÒªÔÚ±íÖÐËæ»úÈ¡³ö10Ìõ¼Ç¼£¬Èç¹ûʹÓñà³ÌÓïÑÔ½øÐÐÔËËãµÄ»°»áºÜÂé·³¶øÇÒЧÂʵÍÏ¡£ÔÚSql ServerÖÐ×Ô´øÁËrandom()º¯ÊýÓÃÓÚÉú³ÉËæ»úÊý£¬ÆäʵËü»¹×Ô´øÁËÁíÍâÒ»¸öËæ»úº¯Êýnewid();newid()ÔÚɨÃèÿÌõ¼Ç¼ʱ¶¼»áÉú³ÉÒ»¸öËæ»úµÄÖµ£º
Ö´ÐÐselect newid()£»ÔËÐнá¹û
¿ÉÒÔ¿´µ½Õâ²¢²»ÊÇÒ»¸öËæ»úµÄÊý× ......
¼ÙÉèÏÖÔÚNews±íÓÐÒÔÏÂ×Ö¶Î
News_Id,News_Title,News_IsSetTop,News_SetTopTime
ÆäÖÐNews_IsSetTop(char(1))ÊÇ“ÊÇ·ñÖö¥”µÄº¬Ò壻News_SetTopTime(DateTime)ÊÇÖö¥Ê±¼ä£»
ÏÖÔÚҪʵÏÖ£ºÈç¹ûNews_IsSetTopΪ"1"ʱ £¬ORDER BY News_IsSetTop DESC,News_Id DESC£»News_IsSetTopΪ"0"ʱ£¬ORDER BY News_ID DESC ......
--Óï ¾ä ¹¦ ÄÜ
--Êý¾Ý²Ù×÷
SELECT --´ÓÊý¾Ý¿â±íÖмìË÷Êý¾ÝÐкÍÁÐ
INSERT --ÏòÊý¾Ý¿â±íÌí¼ÓÐÂÊý¾ÝÐÐ
DELETE --´ÓÊý¾Ý¿â±íÖÐɾ³ýÊý¾ÝÐÐ
UPDATE --¸üÐÂÊý¾Ý¿â±íÖеÄÊý¾Ý
--Êý¾Ý¶¨Òå
CREATE TABLE --´´½¨Ò»¸öÊý¾Ý¿â±í
DROP TABLE --´ÓÊý¾Ý¿âÖÐɾ³ý±í
ALTER TABLE --ÐÞ¸ÄÊý¾Ý¿â±í½á¹¹
CREATE VIEW --´´½¨Ò»¸öÊÓͼ
DRO ......
ÓÐЩ³£¼ûµÄÎÊÌâÔÚÂÛ̳Öв»¶Ï³öÏÖ£¬²»·ÁÕûÀíһϡ£
ÒÔÏÂÓï¾äÊÇÔÚSQLServer2005ÉÏʵÏֵģ¬Ò»Ð©Óï¾äÎÞ·¨ÔÚSS2000ÉÏÖ´ÐС£
ÓÐÓÃÖ¸ÊýÊÇÎÒ¸ù¾ÝÕâ¸öÎÊÌâµÄ³£¼û³Ì¶È´òµÄ·Ö£¬½ö¹©²Î¿¼¡£Êµ¼ÊÉÏ£¬µ±ÄãÓöµ½ÁËÕâ¸öÎÊÌ⣬Õâ¸öÎÊÌâÄÄÅÂÔÙÉÙ¼û£¬½â¾ö·½°¸Ò²ÊǷdz£ÓÐÓõġ£
1. Éú³ÉÈô¸ÉÐмǼ
ÓÐÓÃÖ¸Êý£º¡ï¡ï¡ï¡ï¡ï
³£¼ûµÄÎÊÌâÀàÐÍ£º¸ù ......