mysqlÖÐhavingÊÇʲôÒâ˼
having ×Ó¾äÓÃÓÚ¶Ô·Ö×éºóÊý¾ÝµÄ¾ÛºÏЧ¹û¾ÙÐйýÂË£¬ÒÔÏÂʾÀý˵Ã÷ÆäÓ÷¨£º¶Ô¿Í»§ÏúÊÛÊý¾Ý·Ö×éºó£¬Ö»Ñ¡Ôñ×ÜÏúÊÛ¶î´óÓÚ 10,000 µÄ¿Í»§¡£×÷Óòî±ð£ºwhere ×Ó¾ä¹ýÂ˵¥¸öÐУ¬having ×Ó¾ä¹ýÂ˾ۺÏÖµ¡£Ö´ÐÐ˳Ðò²î±ð£ºwhere ÏÈÖ´ÐУ¬having ºóÖ´ÐС£¿ÉʹÓþۺϺ¯Êý£¬Ìá¸ßÐÔÄܲ¢Ìṩ¸üÎÞаµÄ¹ýÂËÌõ¼þ¡£
MySQL ÖÐµÄ HAVING ×Ó¾ä
ʲôÊÇ HAVING ×Ӿ䣿
HAVING ×Ó¾äÓÃÓڶԾۺϺ¯ÊýµÄЧ¹û¾ÙÐйýÂË¡£Ëü½öÔÚ GROUP BY ×Ó¾äÖ®ºóʹÓ㬶ԷÖ×éºóµÄÊý¾Ý¾ÙÐÐÌõ¼þɸѡ¡£
HAVING ×Ó¾äµÄÓï·¨
SELECT ¾ÛºÏº¯Êý(ÁÐÃû) FROM ±íÃû GROUP BY ·Ö×éÁÐÃû HAVING Ìõ¼þ
µÇ¼ºó¸´ÖÆ
Ìõ¼þ ¿ÉÒÔÊǽÏÁ¿ÔËËã·û¡¢Âß¼ÔËËã·ûºÍ¾ÛºÏº¯Êý¡£
ÒÔÏÂʾÀý˵Ã÷ HAVING ×Ó¾äµÄÓ÷¨£º
SELECT SUM(sales) AS ×ÜÏúÊÛ¶î FROM ¶©µ¥ GROUP BY ¿Í»§ID HAVING ×ÜÏúÊÛ¶î > 10000;
µÇ¼ºó¸´ÖÆ
´ËÅÌÎʽ«ÔÚ¶Ô¿Í»§ÏúÊÛÊý¾Ý¾ÙÐзÖ×éºó£¬Ö»Ñ¡Ôñ×ÜÏúÊÛ¶î´óÓÚ 10,000 µÄ¿Í»§¡£
HAVING Óë WHERE Ö®¼äµÄÇø±ð
×÷Óòî±ð£ºWHERE ×Ó¾ä¹ýÂ˵¥¸öÐеÄÌõ¼þ£¬¶ø HAVING ×Ó¾ä¹ýÂË·Ö×éºóµÄ¾ÛºÏÖµ¡£
Ö´ÐÐ˳Ðò²î±ð£ºWHERE ×Ó¾äÔÚ·Ö×é֮ǰִÐУ¬¶ø HAVING ×Ó¾äÔÚ·Ö×éÖ®ºóÖ´ÐС£
¾ÛºÏº¯ÊýʹÓãºHAVING ×Ó¾äÖпÉÒÔʹÓþۺϺ¯Êý£¬¶ø WHERE ×Ó¾äÖв»¿ÉÒÔ¡£
HAVING ×Ó¾äµÄÓŵã
Ìá¸ßÐÔÄÜ£ºÍ¨¹ýÔÚ·Ö×éºó¹ýÂËÊý¾Ý£¬HAVING ×Ó¾ä¿ÉÒÔïÔÌÐèÒªÅÌËãºÍ´«ÊäµÄÊý¾ÝÁ¿£¬´Ó¶øÌá¸ßÅÌÎÊÐÔÄÜ¡£
¸üÎÞаµÄ¹ýÂË£ºHAVING ×Ó¾äÔÊÐí¶Ô·Ö×éºóµÄÊý¾Ý¾ÙÐÐÖØ´óµÄ¹ýÂË£¬ÕâÔÚʹÓà WHERE ×Ó¾äʱ¿ÉÄÜÎÞ·¨ÊµÏÖ¡£
¿ÉÖظ´Ê¹ÓãºHAVING ×Ó¾ä¿ÉÒÔƾ֤ÅÌÎÊÐèÒªÖظ´Ê¹Óã¬ÎÞÐèÐÞ¸ÄÖ÷ÅÌÎÊ¡£
ÒÔÉϾÍÊÇmysqlÖÐhavingÊÇʲôÒâ˼µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡