SQL SUBSTRINGµÄÓ÷¨
SQL ÖÐµÄ substring º¯ÊýÊÇÓÃÀ´×¥³öÒ»¸öÀ¸Î»×ÊÁÏÖеÄÆäÖÐÒ»²¿·Ö¡£Õâ¸öº¯ÊýµÄÃû³ÆÔÚ²»Í¬µÄ×ÊÁÏ¿âÖв»ÍêÈ«Ò»Ñù£º
MySQL: SUBSTR(), SUBSTRING()
Oracle: SUBSTR()
SQL Server: SUBSTRING()
×î³£Óõ½µÄ·½Ê½ÈçÏ (ÔÚÕâÀïÎÒÃÇÓÃSUBSTR()ΪÀý)£º
SUBSTR(str,pos): ÓÉ<str>ÖУ¬Ñ¡³öËùÓдӵÚ<pos>λÖÿªÊ¼µÄ×ÖÔª¡£Çë×¢Ò⣬Õâ¸öÓï·¨²»ÊÊÓÃÓÚSQL ServerÉÏ¡£
SUBSTR(str,pos,len): ÓÉ<str>ÖеĵÚ<pos>λÖÿªÊ¼£¬Ñ¡³ö½ÓÏÂÈ¥µÄ<len>¸ö×ÖÔª¡£
¼ÙÉèÎÒÃÇÓÐÒÔϵıí¸ñ£º
Geography ±í¸ñ
region_name
store_name
East
Boston
East
New York
West
Los Angeles
West
San Diego
Àý1:
SELECT SUBSTR(store_name, 3)
from Geography
WHERE store_name = 'Los Angeles';
½á¹û:
's Angeles'
Àý2:
SELECT SUBSTR(store_name,2,4)
from Geography
WHERE store_name = 'San Diego';
½á¹û:
'an D'
Ïà¹ØÎĵµ£º
ϵͳ»·¾³£ºWindows 7
Èí¼þ»·¾³£ºVisual C++ 2008 SP1 +SQL Server 2005
±¾´ÎÄ¿µÄ£º±àдһ¸öº½¿Õ¹ÜÀíϵͳ
ÕâÊÇÊý¾Ý¿â¿Î³ÌÉè¼ÆµÄ³É¹û£¬ËäÈ»³É¼¨²»¼Ñ£¬µ«ÊÇ×÷ΪÎÒÓÃVC++ ÒÔÀ´±àдµÄ×î´ó³ÌÐò»¹ÊÇ´«µ½ÍøÉÏ£¬ÒÔ¹©²Î¿¼¡£ÓÃVC++ ×öÊý¾Ý¿âÉè¼Æ²¢²»ÈÝÒ×£¬µ«Ò²²»ÊDz»¿ÉÄÜ¡£ÒÔÏÂÊÇÎҵijÌÐò½çÃ棬ºóÃæ ......
ÎÒÃDz¢²»Ò»¶¨Ã¿Ò»´Î¶¼Òª½«±í¸ñÄÚµÄ×ÊÁ϶¼Íêȫץ³ö¡£ÔÚÐí¶àʱºò£¬ÎÒÃÇ»áÐèҪѡÔñÐÔµØ×¥×ÊÁÏ¡£¾ÍÎÒÃǵÄÀý×ÓÀ´Ëµ£¬ÎÒÃÇ¿ÉÄÜֻҪץ³öÓªÒµ¶î³¬¹ý $1,000 µÄ×ÊÁÏ¡£Òª×öµ½ÕâÒ»µã£¬ÎÒÃǾÍÐèÒªÓõ½ WHERE Õâ¸öÖ¸Áî¡£Õâ¸öÖ¸ÁîµÄÓï·¨ÈçÏ£º
SELECT "À¸Î»Ãû"
from "±í¸ñÃû"
WHERE "Ìõ¼þ"
ÈôÎÒÃÇÒªÓÉÒÔϵıí¸ñ×¥³öÓªÒµ¶î³¬¹ý $1, ......
¼ÈÈ»Êý¾Ý¿âÖÐÓÐÐí¶à×ÊÁ϶¼ÊÇÒÑÊý×ÖµÄÐÍ̬´æÔÚ£¬Ò»¸öºÜÖØÒªµÄÓÃ;¾ÍÊÇÒªÄܹ»¶ÔÕâЩÊý×Ö×öһЩÔËË㣬ÀýÈ罫ËüÃÇ×ܺÏÆðÀ´£¬»òÊÇÕÒ³öËüÃǵÄƽ¾ùÖµ¡£SQL ÓÐÌṩһЩÕâÒ»ÀàµÄº¯Êý¡£ËüÃÇÊÇ£º
AVG (ƽ¾ù)
COUNT (¼ÆÊý)
MAX (×î´óÖµ)
MIN (×îСֵ)
SUM (×ܺÏ)
ÔËÓú¯ÊýµÄÓï·¨ÊÇ£º
SELECT "º¯ÊýÃû"("À¸Î»Ãû")
from "± ......
UNION ALL Õâ¸öÖ¸ÁîµÄÄ¿µÄÒ²ÊÇÒª½«Á½¸ö SQL Óï¾äµÄ½á¹ûºÏ²¢ÔÚÒ»Æð¡£ UNION ALL ºÍ UNION ²»Í¬Ö®´¦ÔÚÓÚ UNION ALL »á½«Ã¿Ò»±Ê·ûºÏÌõ¼þµÄ×ÊÁ϶¼ÁгöÀ´£¬ÎÞÂÛ×ÊÁÏÖµÓÐÎÞÖظ´¡£
UNION ALL µÄÓï·¨ÈçÏ£º
[SQL Óï¾ä 1]
UNION ALL
[SQL Óï¾ä 2]
ÎÒÃÇÓúÍÉÏһҳͬÑùµÄÀý×ÓÀ´ÏÔʾ³ö UNION ALL ºÍ UNION µÄ²»Í¬¡£Í¬Ñù¼ÙÉèÎÒÃÇ ......