sqlÖеÄÌõ¼þÅжÏÔõôд
sql ÖеÄÌõ¼þÅжϿÉÓÃÓÚ¹ýÂËÊý¾Ý£¬½ö·µ»ØÖª×ãÖ¸¶¨Ìõ¼þµÄÐС£where ×Ó¾äÓÃÓÚ¹ýÂËÐУ¬having ×Ó¾äÓÃÓÚ¹ýÂ˾ۺϺ¯ÊýÌìÉúµÄ×éЧ¹û¼¯ÖеÄÐС£Ìõ¼þÅжÏʹÓü´ÊÇ¡¢²»¼´ÊÇ¡¢´óÓÚ¡¢Ð¡ÓÚµÈÔËËã·ûÒÔ¼° and¡¢or¡¢not µÈÂß¼ÔËËã·û¡£¿ÉÒÔǶÌ×Ìõ¼þÒÔ½¨Éè¸üÖØ´óµÄ¹ýÂËÌõ¼þ£¬Ç¶Ì×Ìõ¼þµÄÓÅÏȼ¶×ñÕÕÀ¨ºÅÄÚÌõ¼þ¡¢not ÔËËã·û¡¢and ÔËËã·û¡¢or ÔËËã·û¡£
SQL ÖеÄÌõ¼þÅжÏ
Ìõ¼þÅжÏÊÇ SQL ÅÌÎÊÖÐÓÃÓÚ¹ýÂËÊý¾Ý²¢½ö·µ»ØÖª×ãÌض¨Ìõ¼þµÄÐС£SQL ÖÐÓÐÁ½ÖÖÖ÷ÒªµÄÌõ¼þÅжϣº
WHERE ×Ӿ䣺ÓÃÓÚ¹ýÂËÐУ¬Ö»·µ»ØÖª×ãÖ¸¶¨Ìõ¼þµÄÐС£
HAVING ×Ӿ䣺ÓÃÓÚ¹ýÂËÓɾۺϺ¯Êý£¨Èç SUM¡¢COUNT »ò AVG£©ÌìÉúµÄ×éЧ¹û¼¯ÖеÄÐС£
WHERE ×Ó¾ä
WHERE ×Ó¾äλÓÚ SELECT Óï¾äµÄĩ⣬ÓÃÓÚÖ¸¶¨¹ýÂËÌõ¼þ¡£Ìõ¼þÓÉÒ»¸öÂß¼±í´ïʽ×é³É£¬¸Ã±í´ïʽ¶ÔÐеÄÁÐÇóÖµ£¬²¢·µ»Ø TRUE »ò FALSE¡£
Óï·¨£º
SELECT column_name(s) FROM table_name WHERE condition;
µÇ¼ºó¸´ÖÆ
ʾÀý£º
SELECT * FROM customers WHERE age > 18;
µÇ¼ºó¸´ÖÆ
HAVING ×Ó¾ä
HAVING ×Ó¾äλÓÚ GROUP BY ×Ó¾äÖ®ºó£¬ÓÃÓÚ¹ýÂËÓɾۺϺ¯ÊýÌìÉúµÄ×éЧ¹û¼¯ÖеÄÐС£Ìõ¼þ¶Ô¾ÛºÏÖµÇóÖµ£¬²¢·µ»Ø TRUE »ò FALSE¡£
Óï·¨£º
SELECT column_name(s) FROM table_name GROUP BY group_column(s) HAVING condition;
µÇ¼ºó¸´ÖÆ
ʾÀý£º
SELECT department_id, AVG(salary) FROM employees GROUP BY department_id HAVING AVG(salary) > 50000;
µÇ¼ºó¸´ÖÆ
Ìõ¼þÔËËã·û
SQL ʹÓÃÒÔÏÂÔËËã·û¾ÙÐÐÌõ¼þÅжϣº
¼´ÊÇ£º =
²»¼´ÊÇ£º »ò !=
´óÓÚ£º >
СÓÚ£º
´óÓÚ»ò¼´ÊÇ£º >=
СÓÚ»ò¼´ÊÇ£º
LIKE£ºÓÃÓÚÆ¥Åäģʽ£¨ÀýÈ磬”LIKE ‘%john%'” Æ¥Åä°üÀ¨ “john” ×Ö·û´®µÄÐУ©
Âß¼ÔËËã·û
SQL ʹÓÃÒÔÏÂÂß¼ÔËËã·û×éºÏÌõ¼þ£º
AND£ºÂß¼ÓëÔËËã·û£¬Ö»ÓÐÁ½¸öÌõ¼þ¶¼Îª TRUE ʱ²Å·µ»Ø TRUE¡£
OR£ºÂß¼»òÔËËã·û£¬Ö»ÒªÓÐÒ»¸öÌõ¼þΪ TRUE ʱ¾Í·µ»Ø TRUE¡£
NOT£ºÂß¼·ÇÔËËã·û£¬½«Ìõ¼þЧ¹ûÈ¡·´¡£
ǶÌ×Ìõ¼þ
¿ÉÒÔʹÓÃÀ¨ºÅǶÌ×Ìõ¼þÒÔ½¨Éè¸üÖØ´óµÄ¹ýÂËÌõ¼þ¡£Ç¶Ì×Ìõ¼þµÄÓÅÏȼ¶×ñÕÕÈçÏÂ˳Ðò£º
À¨ºÅÄÚµÄÌõ¼þ
NOT ÔËËã·û
AND ÔËËã·û
OR ÔËËã·û
ÒÔÉϾÍÊÇsqlÖеÄÌõ¼þÅжÏÔõôдµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡