ÎÒÃÇ¿ª·¢Êý¾Ý¿âÓ¦ÓÃʱ£¬³£³£ÐèÒªÓõ½Ä£ºý²éѯ¡£Èç¹ûͬһ¸öÌõ¼þÐèҪƥÅäºÜ¶à×Ö¶ÎÔõô°ìÄØ£¿Í¨³££¬³ÌÐòÔ±»áÿ¸ö×ֶζ¼ÔÚSQLÖГfield like'%cond%'”Ò»´Î¡£ÕâÑù£¬SQLÓï¾ä»á³¤µÃ¾ªÈË£¬ÅöÉϸ´ÔÓÒ»µãµÄ£¬ÉõÖÁSQLÓï¾ä»áÒòΪ³¬³¤¶ø±»Êý¾Ý¿â¾Ü¾øÖ´ÐС£Æäʵ£¬Õâ¸öÎÊÌâÖ»Òª¶¯¶¯ÄÔ½î¾ÍºÜÈÝÒ×½â¾ö£ºÊ×ÏÈ£¬½«ÒªÆ¥ÅäÏàͬÌõ¼þµÄ×Ö¶ÎÁ¬ÆðÀ´(field1+field2+...)³ÉÒ»¸ö³¤×Ö·û´®£»È»ºóÔÙ Like “%cond%”¾Í¿ÉÒÔÁË¡£²»¹ýÕâÖÖ·½·¨ÓиöÎÊÌ⣬¾ÍÊǵÃȨºâ¶à±íÁ¬½ÓÔì³ÉµÄЧÂʽµµÍ¡£Ò»°ãÀ´Ëµ£¬µ¥±íÄÚ×ֶο϶¨Ó¦¸ÃÁ¬½ÓºóÔÙͳһlikeÅжϣ»±í¼ä×ֶΣ¬ÔòÐèÒªÏȹýÂ˺ó£¬ÔÙʵÐÐÕâ¸ö²ßÂÔ¡£²ÉÈ¡Õâ¸ö²ßÂÔ£¬²»½ö¿ÉÒÔËõ¶ÌSQL£¬¶øÇÒÄܹ»ÓÐЧµØÌá¸ßSQLµÄÖ´ÐÐЧÂÊ¡£
Àý£º
| ÒÔÏÂΪÒýÓõÄÄÚÈÝ£º QUOTE:
create table orders (
id int not null auto_increment, name varchar(100) not null, email varchar(255) not null, address text not null, pay_type char(10) not null, shipped_at datetime null, primary key (id) ); |
ÀïÃæÓÐÊý¾Ý
1 aaa aaa@gmail.com beijing cc 2006-10-11 16:17:26
ÏÖÔÚÏëÒª²éÕÒ³öemailΪaaa¿ªÍ·µÄ£¬addressΪbei¿ªÍ·µÄ¼Ç¼
ÄÇôһ°ãÎÒÃǻṹ½¨ÈçÏÂSQL
select * from orders o where o.email like "aaa%" and o.address like "bei%"
ÆäʵÎÒÃÇ¿ÉÒÔʹÓÃÈçÏÂSQLÀ´Ëõ¶ÌSQLÓï¾ä£¨Ò²¾ÍÊÇÁ¬½Ó×Ö¶ÎÒ»Æð½øÐÐlike²Ù×÷£©
SELECT * FROM orders o where concat(o.email,o.address) like "like%df%"
¶à±íµÄÇé¿öÒâ˼ÊÇ˵where×Ó¾äÏÈдÁ¬½Ó×Ӿ佸ÐйýÂËÔÙдÁ¬½ÓlikeÓï¾ä½øÐмìË÷
±ÈÈ磺
SELECT * FROM line_items l,orders o where l.order_id=o.id and concat(l.quantity,o.email) like "3%like%"
ÆäÖÐline_items±í
| ÒÔÏÂΪÒýÓõÄÄÚÈÝ£º create table line_items ( id int not null auto_increment, product_id int not null, order_id int not null, quantity int not null default 0, unit_price decimal(10,2) not null, constraint fk_items_product foreign key (product_id) references products(id), constraint fk_items_order foreign key (order_id) references orders(id), primary key (id) ); |

RSS¶©ÔÄ