sqlÖÐwhereÓï¾äµÄд·¨
sql where Óï¾äÓÃÓÚ´Ó±íÖÐɸѡÇкÏÌض¨Ìõ¼þµÄÐУ¬ÆäÓ﷨Ϊ£ºselect ×Ö¶ÎÁбí from ±íÃû where Ìõ¼þ±í´ïʽ¡£Ìõ¼þ±í´ïʽÓɲ¼¶û±í´ïʽºÍ²¼¶ûÔËËã·û£¨and¡¢or¡¢not£©×é³É¡£²¼¶û±í´ïʽͨ³£ÓɽÏÁ¿ÔËËã·û£¨=¡¢!=¡¢=£©ºÍÔËËãÊý£¨±íÁÐÖµ¡¢×ÓÅÌÎÊ£©×é³É¡£
SQL WHERE Óï¾äµÄд·¨
WHERE Óï¾äÓÃÓÚ´Ó±íÖÐɸѡ֪×ãÌض¨Ìõ¼þµÄÐС£ÆäÓï·¨ÈçÏ£º
SELECT column_list FROM table_name WHERE condition;
µÇ¼ºó¸´ÖÆ
Ìõ¼þ±í´ïʽ
Ìõ¼þ±í´ïʽÓÃÓÚÖ¸¶¨É¸Ñ¡Ìõ¼þ¡£Ìõ¼þ±í´ïʽÓÉÒ»¸ö»ò¶à¸ö²¼¶û±í´ïʽ×é³É£¬²¼¶û±í´ïʽÒÔ²¼¶ûÔËËã·û AND¡¢OR ºÍ NOT ÅþÁ¬¡£
AND£º½öµ±ËùÓв¼¶û±í´ïʽ¶¼ÎªÕæʱ£¬Ìõ¼þ±í´ïʽ²ÅΪÕæ¡£
OR£ºµ±ÖÁÉÙÒ»¸ö²¼¶û±í´ïʽΪÕæʱ£¬Ìõ¼þ±í´ïʽ²ÅΪÕæ¡£
NOT£ºµ±²¼¶û±í´ïʽΪ¼Ùʱ£¬Ìõ¼þ±í´ïʽ²ÅΪÕæ¡£
²¼¶û±í´ïʽ
²¼¶û±í´ïʽͨ³£ÓɽÏÁ¿ÔËËã·ûºÍÔËËãÊý×é³É¡£½ÏÁ¿ÔËËã·û°üÀ¨£º
=£º¼´ÊÇ
!=£º²»¼´ÊÇ
>£º´óÓÚ
>=£º´óÓÚ»ò¼´ÊÇ
ÔËËãÊý¿ÉÒÔÊÇ£º
±íÁÐ
Öµ
×ÓÅÌÎÊ
ʾÀý
ÒÔÏÂʾÀý´Ó customers ±íÖÐɸѡ³öÆÜÉíÔÚ “Seattle” ¶¼»áµÄ¿Í»§£º
SELECT * FROM customers WHERE city = 'Seattle';
µÇ¼ºó¸´ÖÆ
ÒÔÏÂʾÀý´Ó orders ±íÖÐɸѡ³ö×ܼÛÁè¼Ý 500 ÃÀÔªµÄ¶©µ¥£º
SELECT * FROM orders WHERE total_price > 500;
µÇ¼ºó¸´ÖÆ
ÒÔÏÂʾÀý´Ó employees ±íÖÐɸѡ³öÐÕÃûÒÔ “J” ¿ªÍ·µÄÔ±¹¤£º
SELECT * FROM employees WHERE name LIKE 'J%';
µÇ¼ºó¸´ÖÆ
ÒÔÉϾÍÊÇsqlÖÐwhereÓï¾äµÄд·¨µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡