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

SQL Ëæ»ú³éÑùµÄ×ܽá

¶ÔÓÚSQL Ëæ»ú³éÑùÎÒÃdz£Ïëµ½µÄ¾ÍÊÇnewid()£¬µ«Èç¹û¶ÔÓÚÒ»¸öÔÚ°ÙÍò¡¢Ç§ÍòÉõÖÁ¸ü´óº£Á¿Êý¾Ý±íÖгéÑùµÄ»°£¬¼òµ¥µÄnewid()£¬ÆäÐÔÄÜ£¬Ð§ÂʾͲ»ÊǺÜÀíÏëÁË¡£ËùÒÔÔÚÕâÀïÓбØÒªÌÖÂÛһϣ¬ÔñÓŶøÓá£
 
long_goodsÊÇÒ»¸ö°ÙÍòÊý¾ÝµÄ±í£¬Ctrl+LÖ´ÐÐÒÔÏÂÓï¾ä:
 
--id_indexÊÇÎÒΪÖ÷¼ü¼ÓµÄÒ»¸ö·Ç¾Û½¹Ë÷Òý
SELECT top 1  * from long_goods order by newid()
--²éѯ¿ªÏú 43%
SELECT top 1  * from long_goods with(index=id_index) order by newid()
--²éѯ¿ªÏú 54%
select top 1 * from long_goods where id=(select top 1 id from long_goods order by newid())
--²éѯ¿ªÏú 1%
select top 1 * from long_goods where id=(select top 1 id from long_goods with(index=id_index) order by newid())
--²éѯ¿ªÏú 1%
 
ËäÈ»µÚÈý¸öÓëµÚËĸöµÄ¿ªÏúÊÇÒ»Ñù£¬µ«Êµ¼ÊÓ¦¸ÃÊǵÚËÄÖÖÓÅÓÚµÚÈýÖÖ¡£
 
Èç¹ûMS SQL2005Éý¼¶µ½Ö§³Ö TABLESAMPLE µÄ»°£¬ÒÔÏÂÓï¾äµÄ³éÑùÖ´ÐÐЧÂÊ¿ÉΪ×îÓŵÄ
SELECT * from long_goods TABLESAMPLE SYSTEM (10 PERCENT)
 
ºÇºÇ..Ï°àÁË£¬ÖÁÓÚÆäÖÐÔ­Òò£¬Ï´ÎÓпÕÔÙÐø.


Ïà¹ØÎĵµ£º

SqlÓï¾äѧϰ±Ê¼Ç(4) ²éѯ1

ÕâÀïʹÓõÄÊý¾Ý¿âºÍÊý¾Ý±í·Ö±ðÀ´×ÔSqlÓï¾äѧϰ±Ê¼Ç£¨1£©——´´½¨Êý¾Ý¿âºÍSqlÓï¾äѧϰ±Ê¼Ç£¨2£©——´´½¨Êý¾Ý±í
use RetalDB
/********************
µ¥±í²éѯ
*********************/
--²éѯtb_userÖеÄÊý¾Ý£ºÎÞÌõ¼þ²éѯ
--(1)
select * from tb_user--²éѯËùÓÐÐÅÏ¢
--(2)
select top 2 * from ......

ʹÓÃSQLÓï¾äÉú³ÉÊý¾Ý×Öµä

--sqlserver 2000
SELECT ±íÃû=case when a.colorder=1 then d.name else '' end,
--×Ö¶ÎÐòºÅ=a.colorder,
×Ö¶ÎÃû=a.name,
--
±êʶ=case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '√'else '' end,
/**/
Ö÷¼ü=case when exists(SELECT 1 from sysobjects where xtype='PK' and name
in ( ......

sqlÓï¾äѧϰ±Ê¼Ç(5) sqlÓï·¨

1.sqlÊÇÒ»Öֽű¾ÓïÑÔ
2.sql¿Éд½Å±¾³ÌÐò£¬µ«×îÖØÒªµÄ×÷Ó÷¢»ÓÔÚ¶ÔÊý¾Ý¿âµÄ²Ù×÷ÉÏ
3.sql server2005ÖеÄ×¢ÊÍÓÐÁ½ÖÖ/***/¶àÐÐ×¢ÊÍ£¬--¿ÉÒÔµ¥ÐÐ×¢ÊÍ
4.sqlÖеÄ×Ô¶¨Òå±äÁ¿ÒÔ@¿ªÍ·£¬ÏµÍ³±äÁ¿ÒÔ@@¿ªÍ·
5.sqlÖÐÉùÃ÷±äÁ¿ºÍVBÀàËÆ£¬Ê¹ÓÃdeclareÉùÃ÷±äÁ¿È磺declare @i int,@j int£¬´ËÓï¾äÉùÃ÷ÁË2¸öÕûÐαäÁ¿@iºÍ@j
6.sqlÖеÄÊý¾Ý ......

PL/SQL ÖеÄSQLÓï¾ä

ÀýÈ磺
ÆÕ±éµÄSQLÓï¾ä£º
          update book set bookname='sssss' where bookId=1;   
ÔÚPL/SQL ÖÐÖ´ÐУº 
          declare
           v_book ......

dz̸SQL½Ì³ÌÖ®Group byºÍHaving

ÔÚ½éÉÜGROUP BY ºÍ HAVING ×Ó¾äÇ°£¬ÎÒÃDZØÐèÏȽ²½²sqlÓïÑÔÖÐÒ»ÖÖÌØÊâµÄº¯Êý£º¾ÛºÏº¯Êý£¬ÀýÈçSUM, COUNT, MAX, AVGµÈ¡£ÕâЩº¯ÊýºÍÆäËüº¯ÊýµÄ¸ù±¾Çø±ð¾ÍÊÇËüÃÇÒ»°ã×÷ÓÃÔÚ¶àÌõ¼Ç¼ÉÏ¡£
      SELECT SUM(population) from bbc
¡¡¡¡ÕâÀïµÄSUM×÷ÓÃÔÚËùÓзµ»Ø¼Ç¼µÄpopulation×Ö¶ÎÉÏ£¬½á¹û¾ÍÊǸòéÑ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ