sqlÖеÄlikeÊÇʲôÒâ˼
sql ÖÐµÄ like ÔËËã·ûÓÃÓÚÑ°ÕÒÆ¥ÅäÌض¨Ä£Ê½µÄÖµ£¬ËüʹÓÃͨÅä·û %£¨Æ¥Åäí§Òâ×Ö·û£©ºÍ _£¨Æ¥Åäµ¥¸ö×Ö·û£©¡£like ÔËËã·ûͨ³£Óë where ×Ó¾äÍŽáʹÓã¬ÓÃÓÚ¹ýÂ˱íÖеÄÐУ¬×¢ÖØËüÇø·Ö¾Þϸд£¬ÇÒͨÅä·ûÖ»ÄÜÔÚģʽ¿ªÍ·»ò×îºóʹÓá£
SQL ÖÐµÄ LIKE ÊÇʲô£¿
LIKE ÔËËã·ûÔÚ SQL ÖÐÓÃÓÚÑ°ÕÒÓëÌض¨Ä£Ê½ÏàÆ¥ÅäµÄÖµ¡£ËüʹÓÃͨÅä·û %£¨°Ù·ÖºÅ£©ºÍ _£¨Ï»®Ïߣ©£¬ÔÊÐíÄúÖ¸¶¨ÒªËÑË÷µÄÖµµÄÌض¨²¿·Ö¡£
°Ù·ÖºÅ£¨%£©
°Ù·ÖºÅÆ¥ÅäÈκÎÊýÄ¿µÄ×Ö·û¡£ÀýÈ磬LIKE ‘%john%’ ½«Æ¥Åä john¡¢john smith¡¢johnny µÈÖµ¡£
Ï»®Ïߣ¨_£©
Ï»®ÏßÆ¥Åäµ¥¸ö×Ö·û¡£ÀýÈ磬LIKE ‘j_hn’ ½«Æ¥Åä john£¬µ«²»»áÆ¥Åä johnny¡£
ʹÓà LIKE ÔËËã·û
LIKE ÔËËã·ûͨ³£Óë WHERE ×Ó¾äÍŽáʹÓã¬ÓÃÓÚ¹ýÂ˱íÖеÄÐС£Óï·¨ÈçÏ£º
SELECT column_name(s) FROM table_name WHERE column_name LIKE 'pattern';
µÇ¼ºó¸´ÖÆ
ʾÀý
²éÕÒ±í customers ÖÐÐÕÃû°üÀ¨ “john” µÄËùÓпͻ§£º
SELECT name FROM customers WHERE name LIKE '%john%';
µÇ¼ºó¸´ÖÆ
×¢ÖØÊÂÏî
LIKE ÔËËã·ûÇø·Ö¾Þϸд¡£
% ºÍ _ ͨÅä·ûÖ»ÄÜÔÚģʽµÄĩβ»ò¿ªÍ·Ê¹Óá£
ÈôÊÇÐèÒªÔÚģʽÖвéÕÒ % »ò _ ×Ö·û£¬ÇëʹÓÃתÒå×Ö·û \£¨·´Ð±¸Ü£©¡£ÀýÈ磬LIKE ‘\\%john’ ½«Æ¥Åä %john¡£
ÒÔÉϾÍÊÇsqlÖеÄlikeÊÇʲôÒâ˼µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡