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

sql ³£ÓþۺϺ¯Êý

8.2  ¾ÛºÏº¯ÊýµÄÓ¦ÓÃ
¾ÛºÏº¯ÊýÔÚÊý¾Ý¿âÊý¾ÝµÄ²éѯ·ÖÎöÖУ¬Ó¦ÓÃÊ®·Ö¹ã·º¡£±¾½Ú½«·Ö±ð¶Ô¸÷¾ÛºÏº¯ÊýµÄÓ¦ÓýøÐÐ˵Ã÷¡£
8.2.1  ÇóºÍº¯Êý——SUM()
ÇóºÍº¯ÊýSUM( )ÓÃÓÚ¶ÔÊý¾ÝÇóºÍ£¬·µ»ØÑ¡È¡½á¹û¼¯ÖÐËùÓÐÖµµÄ×ܺ͡£Óï·¨ÈçÏ¡£
SELECT          SUM(column_name)
from            table_name
˵Ã÷£ºSUM()º¯ÊýÖ»ÄÜ×÷ÓÃÓÚÊýÖµÐÍÊý¾Ý£¬¼´ÁÐcolumn_nameÖеÄÊý¾Ý±ØÐëÊÇÊýÖµÐ͵ġ£
ʵÀý1  SUMº¯ÊýµÄʹÓÃ
´ÓTEACHER±íÖвéѯËùÓÐÄнÌʦµÄ¹¤×Ê×ÜÊý¡£TEACHER±íµÄ½á¹¹ºÍÊý¾Ý¿É²Î¼û5.2.1½ÚµÄ±í5-1£¬ÏÂͬ¡£ÊµÀý´úÂ룺
SELECT SUM(SAL) AS BOYSAL
from    TEACHER
WHERE   TSEX='ÄÐ'
ÔËÐнá¹ûÈçͼ8.1Ëùʾ¡£
ͼ8.1  TEACHER±íÖÐËùÓÐÄнÌʦµÄ¹¤×Ê×ÜÊý
ʵÀý2  SUMº¯Êý¶ÔNULLÖµµÄ´¦Àí
´ÓTEACHER±íÖвéѯÄêÁä´óÓÚ40ËêµÄ½ÌʦµÄ¹¤×Ê×ÜÊý¡£ÊµÀý´úÂ룺
SELECT SUM(SAL) AS OLDSAL
from    TEACHER
WHERE   AGE>=40
ÔËÐнá¹ûÈçͼ8.2Ëùʾ¡£
ͼ8.2  TEACHER±íÖÐËùÓÐÄêÁä´óÓÚ40ËêµÄ½ÌʦµÄ¹¤×Ê×ÜÊý
µ±¶ÔijÁÐÊý¾Ý½øÐÐÇóºÍʱ£¬Èç¹û¸ÃÁдæÔÚNULLÖµ£¬ÔòSUMº¯Êý»áºöÂÔ¸ÃÖµ¡£
8.2.2  ¼ÆÊýº¯Êý——COUNT()
COUNT()º¯ÊýÓÃÀ´¼ÆËã±íÖмǼµÄ¸öÊý»òÕßÁÐÖÐÖµµÄ¸öÊý£¬¼ÆËãÄÚÈÝÓÉSELECTÓï¾äÖ¸¶¨¡£Ê¹ÓÃCOUNTº¯Êýʱ£¬±ØÐëÖ¸¶¨Ò»¸öÁеÄÃû³Æ»òÕßʹÓÃÐǺţ¬ÐǺűíʾ¼ÆËãÒ»¸ö±íÖеÄËùÓмǼ¡£Á½ÖÖʹÓÃÐÎʽÈçÏ¡£
     COUNT(*)£¬¼ÆËã±íÖÐÐеÄ×ÜÊý£¬¼´Ê¹±íÖÐÐеÄÊý¾ÝΪNULL£¬Ò²±»¼ÆÈëÔÚÄÚ¡£
     COUNT(column)£¬¼ÆËãcolumnÁаüº¬µÄÐеÄÊýÄ¿£¬Èç¹û¸ÃÁÐÖÐijÐÐÊý¾ÝΪNULL£¬Ôò¸ÃÐв»¼ÆÈëͳ¼Æ×ÜÊý¡£
1£®Ê¹ÓÃCOUNT(*)º¯Êý¶Ô±íÖеÄÐÐÊý¼ÆÊý
COUNT(*)º¯Êý½«·µ»ØÂú×ãSELECTÓï¾äµÄWHERE×Ó¾äÖеÄËÑË÷Ìõ¼þµÄº¯Êý¡£
ʵÀý3  COUNT(*)º¯ÊýµÄʹÓÃ
²éѯTEACHER±íÖеÄËùÓмǼµÄÐÐÊý¡£ÊµÀý´úÂ룺
SELECT COUNT(*) AS TOTALITEM
from    TEACHER
ÔËÐнá¹ûÈçͼ8.3Ëùʾ¡£
ͼ8.3  ʹÓÃCOUNT(*)º¯Êý¶Ô±íÖеÄÐÐÊý¼ÆÊý
ÔÚ¸ÃÀýÖУ¬SELECTÓï¾äÖÐûÓÐWHERE×Ӿ䣬ÄÇôÈÏΪ±íÖеÄËùÓÐÐж¼Âú×ãSELECTÓï¾ä£¬ËùÒÔSELECTÓï¾ä½«·µ»Ø±íÖÐËùÓÐÐеļÆÊý£¬½á¹ûÓë5.2.1½ÚµÄ±í5-1ÁгöµÄTEACHER±íµÄÊý¾ÝÏàÎǺϡ£
Èç¹ûDBMSÔÚÆäϵͳ±íÖд


Ïà¹ØÎĵµ£º

Oracle ѧϰ£ºPL/SQLÑ­Ðò½¥½øÈ«Ãæѧϰ½Ì³Ì

 ¿Î³ÌÊ®¶þ ±àд¿ØÖƽṹÓï¾ä
¡¡¡¡
¡¡¡¡±¾¿ÎÖص㣺
¡¡¡¡1¡¢½á¹¹¿ØÖƵĵÄÓÃ;ºÍÀàÐÍ
¡¡¡¡2¡¢IF ½á¹¹
¡¡¡¡3¡¢¹¹ÔìºÍ±êʶ²»Í¬µÄÑ­»·
¡¡¡¡4¡¢Ê¹ÓÃÂß¼­±í
¡¡¡¡5¡¢¿ØÖÆÁ÷ºÍǶÌ×
¡¡¡¡
¡¡¡¡×¢Ò⣺ÒÔÏÂʵÀýÖбêµã¾ùΪӢÎÄ°ë½Ç
¡¡¡¡
¡¡¡¡Ò»¡¢¿ØÖÆÖ´ÐÐÁ÷
¡¡¡¡¿ÉÒÔÊÇ·ÖÖ§ºÍÑ­»·£ºIF THEN END IF
¡¡¡¡IF condition THEN ......

Oracle ѧϰ£ºPL/SQLÑ­Ðò½¥½øÈ«Ãæѧϰ½Ì³Ì

 ¿Î³ÌÊ®Èý ʹÓÃ×éºÏÊý¾ÝÀàÐÍ* Óαê²Ù×ÝÊý¾Ý
¡¡¡¡
¡¡¡¡±¾¿ÎÖص㣺
¡¡¡¡1¡¢´´½¨Óû§×Ô¶¨ÒåµÄPLSQL¼Ç¼
¡¡¡¡2¡¢ÀûÓÃ%ROWTYPEÊôÐÔÀ´´´½¨¼Ç¼
¡¡¡¡3¡¢´´½¨PLSQL±í
¡¡¡¡4¡¢ÃèÊö¼Ç¼¡¢±í¡¢¼Ç¼µÄ±íÖ®¼äµÄÇø±ð
¡¡¡¡×¢Ò⣺ÒÔÏÂʵÀýÖбêµã¾ùΪӢÎÄ°ë½Ç
¡¡¡¡Ò»¡¢ºÏ³ÉÊý¾ÝÀàÐÍ
¡¡¡¡1¡¢ÀàÐÍ·ÖΪPLSQL¼Ç¼ºÍPLSQL±í
¡¡¡¡2¡ ......

½âÎöMicrosoft Sql ServerÖеÄlikeÓï¾ä


 
 
ʹÓà LIKE µÄģʽƥÅä
 
µ±ËÑË÷ datetime ֵʱ£¬ÍƼöʹÓà LIKE£¬ÒòΪ datetime Ïî¿ÉÄÜ°üº¬¸÷ÖÖÈÕÆÚ²¿·Ö¡£ÀýÈ磬Èç¹û½«Öµ 19981231 9:20 ²åÈëµ½ÃûΪ arrival_time µÄÁÐÖУ¬Ôò×Ó¾ä WHERE arrival_time = 9:20 ½«ÎÞ·¨ÕÒµ½ 9:20 ×Ö·û´®µÄ¾«È·Æ¥Å䣬ÒòΪ SQL Server ½«Æäת»»Îª 1900 Äê 1 Ô 1 ÈÕÉÏÎ ......

ÈçºÎɾ³ý SQL Server ±íÖеÄÖظ´ÐÐ

    Microsoft SQL Server ±í²»Ó¦¸Ã°üº¬Öظ´ÐкͷÇΨһÖ÷¼ü¡£Îª¼ò½àÆð¼û£¬ÔÚ±¾ÎÄÖÐÎÒÃÇÓÐʱ³ÆÖ÷¼üΪ“¼ü”»ò“PK”£¬µ«ÕâʼÖÕ±íʾ“Ö÷¼ü”¡£Öظ´µÄ PK Î¥·´ÁËʵÌåÍêÕûÐÔ£¬ÔÚ¹ØϵϵͳÖÐÊDz»ÔÊÐíµÄ¡£SQL Server Óи÷ÖÖÇ¿ÖÆÖ´ÐÐʵÌåÍêÕûÐԵĻúÖÆ£¬°üÀ¨Ë÷Òý¡¢Î¨Ò»Ô¼Êø¡¢Ö÷¼üÔ¼Êøº ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ