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

¸ß¼¶ SQL 1

1 µ±Ê¹ÓÃgroup byʱ£¬Î´ÔÚgroup by ²¿·ÖÓõ½µÄ±íÁÐÔÚs e l e c t²¿·Ö³öÏÖʱ±ØÐëʹÓ÷Ö×麯Êý¡£
select last_name, state_cd, sum(sales) from customer group by last_name;
ERROR at line 1:
ORA-00979: not a GROUP BY expression.
state_cdÓ¦¸ÃʹÓ÷Ö×麯Êý£¬m a x ( )¡¢m i n ( )¡¢s u m ( )¡¢c o u n t ( )»òa v g ( )º¯Êý¡£·ñÔò°Ñstate_cd·ÅÔÚlast_nameºóÃæ£¬×÷Ϊgroup byµÄÒ»¸öÌõ¼þ¡£
2 having×Ó¾äÔÊÐíÓû§Ö¸¶¨¶ÔÒ»¸ö¼Ç¼×éµÄËÑË÷Ìõ¼þ¡£¶øÍ¨³£µÄwhere²éѯÌõ¼þÖ»Õë¶Ôµ¥¼Ç¼£¬²»Õë¶Ô¼Ç¼×é¡£
¼ÙÈçÖ»ÏëÁ˽â¿Í»§³¬¹ý3 0 0¸öµÄÖÝ£¬Ê¹ÓÃhaving ×Ӿ䣬
select state_cd, sum(sales) from customer group by state_cd having count(state_cd) > 300;
3


Ïà¹ØÎĵµ£º

SQL ServerÖÐpivot and unpivotµÄÓ÷¨ £¨ÐÐÁл¥×ª£©

 .PivotµÄÓ÷¨Ìå»á:
Óï¾ä·¶Àý:
select PN,[2006/5/30] as [20060530],[2006/6/2] as [20060602]
from consumptiondata a
Pivot (sum(a.M_qty) FOR a.M_date in ([2006/5/30],[2006/6/2])) as PVT 
order by PN
 
Table½á¹¹ Consumptiondata (PN,M_Date,M_qty)
order by PN¿ÉÒª¿É²»Òª,²¢²»ÖØ ......

¶¯Ì¬SQLÓ뾲̬SQL

    Ëùν¾²Ì¬SQLÖ¸ÔÚPL/SQL¿éÖÐʹÓõÄSQLÓï¾äÔÚ±àÒëʱÊÇÃ÷È·µÄ£¬Ö´ÐеÄÊÇÈ·¶¨¶ÔÏó¡£¶ø¶¯Ì¬SQLÊÇÖ¸ÔÚPL/SQL¿é±àÒëʱSQLÓï¾äÊDz»È·¶¨µÄ£¬Èç¸ù¾ÝÓû§ÊäÈëµÄ²ÎÊýµÄ²»Í¬¶øÖ´Ðв»Í¬µÄ²Ù×÷¡£±àÒë³ÌÐò¶Ô¶¯Ì¬Óï¾ä²¿·Ö²»½øÐд¦Àí£¬Ö»ÊÇÔÚ³ÌÐòÔËÐÐʱ¶¯Ì¬µØ´´½¨Óï¾ä¡¢¶ÔÓï¾ä½øÐÐÓï·¨·ÖÎö²¢Ö´ÐиÃÓï¾ä¡£
OracleÖж¯Ì¬SQL ......

SQLÖÐtruncate tableºÍdeleteµÄÇø±ð

TRUNCATE TABLE ÔÚ¹¦ÄÜÉÏÓë²»´ø Where ×Ó¾äµÄ Delete
Óï¾äÏàͬ£º¶þÕß¾ùɾ³ý±íÖеÄÈ«²¿ÐС£µ« TRUNCATE TABLE ±È Delete Ëٶȿ죬ÇÒʹÓõÄϵͳºÍÊÂÎñÈÕÖ¾×ÊÔ´ÉÙ¡£
Delete
Óï¾äÿ´Îɾ³ýÒ»ÐУ¬²¢ÔÚÊÂÎñÈÕÖ¾ÖÐΪËùɾ³ýµÄÿÐмǼһÏî¡£TRUNCATE TABLE ͨ¹ýÊÍ·Å´æ´¢±íÊý¾ÝËùÓõÄÊý¾ÝÒ³À´É¾³ýÊý¾Ý£¬²¢ÇÒÖ»ÔÚÊÂÎñÈÕÖ¾ÖмÇÂ¼Ò ......

SQL Server 2005Ö§³ÖµÄÁ½ÌõÐÂÓï·¨

±¾ÎĽéÉÜÁËSQL Server 2005ÖÐÉÙÊýÈËÓõ½µÄÁ½Ìõ¾«Æ·ÐÂÓï·¨£¬´ó¼Ò¿´¿´×Ô¼ºÊÇ·ñÖªµÀÄØ……
¡¡¡¡1. OUTPUT ... INTO
¡¡¡¡ÓÃÓÚ½«Ò»Ìõ¼Ç¼´Ó±íÒ»ÒÆ¶¯µ½±í¶þʱ·Ç³£ºÃÓ㬳£¼ûÓÚ±¸·Ý¼Ç¼µÄÓ¦ÓÃ
¡¡¡¡ÀýÒ»£º
¡¡¡¡DELETE [TableUseing]
¡¡¡¡OUTPUT *
¡¡¡¡INTO [TableBak]
¡¡¡¡Àý¶þ£º(ÓÃÓÚÒÆ¶¯Ê±ÐÞ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ