sqlÖÐlikeÊÇʲôÒâ˼
like ÊÇ sql ÖеIJÙ×÷·û£¬ÓÃÓÚÔÚ±íÖÐËÑË÷ÓëÖ¸¶¨Ä£Ê½ÏàÆ¥ÅäµÄÐС£ËüʹÓÃͨÅä·û % ºÍ À´Æ¥Åä×Ö·û£¬ÆäÖÐ % Æ¥Åäí§ÒâÊýÄ¿µÄ×Ö·û£¬¶ø Æ¥ÅäÈκε¥¸ö×Ö·û¡£
SQL ÖÐµÄ LIKE
ʲôÊÇ LIKE£¿
LIKE ÊÇ SQL ÖеÄÒ»¸ö²Ù×÷·û£¬ÓÃÓÚÔÚÊý¾Ý¿â±íÖÐËÑË÷ÓëÖ¸¶¨Ä£Ê½ÏàÆ¥ÅäµÄÐС£
ʹÓÃÒªÁì
LIKE Óï·¨ÈçÏ£º
SELECT column_name FROM table_name WHERE column_name LIKE 'pattern';
µÇ¼ºó¸´ÖÆ
ÆäÖУº
column_name ÊÇÒªËÑË÷µÄÁÐÃû¡£
pattern ÊÇҪƥÅäµÄģʽ£¬¿ÉÒÔʹÓÃÒÔÏÂͨÅä·û£º
%£ºÆ¥Åäí§ÒâÊýÄ¿µÄ×Ö·û¡£
_£ºÆ¥ÅäÈκε¥¸ö×Ö·û¡£
ÊÂÇéÔÀí
LIKE ÔËËã·ûͨ¹ý½«ÁÐÖµÓëÖ¸¶¨µÄģʽ¾ÙÐнÏÁ¿À´ÊÂÇé¡£ÈôÊÇÁÐÖµÓëģʽƥÅ䣬Ôò¸ÃÐн«±»·µ»Ø¡£
ʾÀý
ÒÔÏÂʾÀýÅÌÎÊ·µ»Ø°üÀ¨×Öĸ “a” µÄËùÖøÃû³ÆµÄÐУº
SELECT name FROM customers WHERE name LIKE '%a%';
µÇ¼ºó¸´ÖÆ
ÒÔÏÂʾÀýÅÌÎÊ·µ»ØÒÔ “J” ¿ªÍ·µÄËùÓÐÐÕÊϵÄÐУº
SELECT last_name FROM customers WHERE last_name LIKE 'J%';
µÇ¼ºó¸´ÖÆ
×¢ÖØ£º
LIKE ÔËËã·û²»Çø·Ö¾Þϸд¡£
LIKE ģʽ±ØÐèÓõ¥ÒýºÅÀ¨ÆðÀ´¡£
ÈôÊÇģʽÖаüÀ¨Í¨Åä·û£¬Ôò±ØÐèÓ÷´Ð±¸Ü () תÒå¡£ÀýÈ磺Ҫ²éÕÒ°üÀ¨×Ö·û “%” µÄÁÐÖµ£¬¿ÉÒÔʹÓÃģʽ \%¡£
ÒÔÉϾÍÊÇsqlÖÐlikeÊÇʲôÒâ˼µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡