{"id":8996,"date":"2022-09-15T07:00:00","date_gmt":"2022-09-15T01:30:00","guid":{"rendered":"https:\/\/selfimagination.in\/tips\/?p=8996"},"modified":"2022-09-10T00:50:11","modified_gmt":"2022-09-09T19:20:11","slug":"having-clause-in-mysql","status":"publish","type":"post","link":"https:\/\/selfimagination.in\/tips\/having-clause-in-mysql\/","title":{"rendered":"MySQL Having Clause"},"content":{"rendered":"\n<p><strong>Having :<\/strong> Aggregate Function \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930 \u0939\u092e \u0915\u093f\u0938 \u092d\u0940 Table \u0915\u0947 Data \u0915\u094b Group \u0915\u0930\u0924\u0947 \u0939\u0948\u0902 \u092f\u093e\u0928\u093f \u0915\u0940 Count, Sum, Avg, Min, Max \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930 Data \u0915\u094b Summerize \u0915\u0930 \u0932\u0947\u0924\u0947 \u0939\u0948\u0902 \u0964  \u092f\u0926\u093f summerize data \u092a\u0930 \u0939\u092e\u0947 \u0915\u094b\u0908 Filter \u0932\u0917\u093e\u0928\u093e \u0939\u094b \u0924\u092c \u0939\u092e Having \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930\u0924\u0947 \u0939\u0948\u0902 \u0964 \u091c\u0948\u0938\u093e \u0939\u092e Row \u0915\u094b Filter \u0915\u0930\u0928\u0947 \u0915\u0947 \u0932\u093f\u090f where \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930\u0924\u0947 \u0939\u0948\u0902 \u0935\u0948\u0938\u0947 \u0939\u0940 Group by \u0915\u0930\u0928\u0947 \u0915\u0947 \u092c\u093e\u0926 \u091c\u094b Aggregate Value \u0939\u094b\u0924\u0940 \u0939\u0948\u0902 \u0909\u0938\u0915\u094b Filter \u0915\u0930\u0928\u0947 \u0915\u0947 \u0932\u093f\u090f \u0939\u092e Having \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930\u0924\u0947 \u0939\u0948\u0902\u0964 <\/p>\n\n\n\n<p><strong>Example :<\/strong> \u091c\u0948\u0938\u0947 \u0939\u092e\u093e\u0930\u0947 \u092a\u093e\u0938 Table \u0939\u0948\u0902 \u091c\u093f\u0938\u092e\u0947 Customer Name, Item Name, Qty \u0914\u0930 Rate \u0939\u0948 \u0964 <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u0905\u092c \u0907\u0938\u092e\u0947 \u0917\u094d\u0930\u0941\u092a \u0935\u093e\u0932\u0947 \u092e\u0947 Having Clause \u0932\u0917\u093e\u092f\u093e \u0939\u0948\u0902 \u091c\u093f\u0938\u092e\u0947 sum \u0939\u094b\u0928\u0947 \u0915\u0947 \u092c\u093e\u0926 \u091c\u094b \u0935\u0948\u0932\u094d\u092f\u0942 \u0906\u0908 \u0939\u0948\u0902 \u0909\u0938 \u092a\u0930 Filter \u0932\u0917\u093e \u0939\u0948\u0902 \u0964 <\/li><li>\u091c\u092c\u0915\u093f Where \u0935\u093e\u0932\u0947 \u092e\u0947 \u092a\u0939\u0932\u0947 \u0939\u0940 where \u0938\u0947 Row Filter \u0939\u094b \u0915\u0930 \u091c\u094b \u0935\u0948\u0932\u094d\u092f\u0942 \u0906\u0908 \u0939\u0948\u0902 \u0909\u0938\u0915\u093e Sum \u0932\u0917\u093e \u0939\u0948\u0902\u0964  <\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"257\" src=\"https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2022\/09\/image-1.png?resize=640%2C257&#038;ssl=1\" alt=\"\" class=\"wp-image-9004\" srcset=\"https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2022\/09\/image-1.png?w=952&amp;ssl=1 952w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2022\/09\/image-1.png?resize=300%2C120&amp;ssl=1 300w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2022\/09\/image-1.png?resize=768%2C308&amp;ssl=1 768w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2022\/09\/image-1.png?resize=150%2C60&amp;ssl=1 150w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Having Apply on Aggregate Values <\/h2>\n\n\n\n<p>\u091c\u092c \u092d\u0940 \u0906\u092a \u0915\u094b\u0908 \u092d\u0940 Aggregate Function \u0932\u0917\u093e\u090f\u0902\u0917\u0947 \u0909\u0938 \u092a\u0930 \u0939\u0940 Having Apply \u0939\u094b\u0924\u093e \u0939\u0948\u0902 \u092c\u093f\u0928\u093e Aggregate \u0915\u0947 \u0939\u092e Row Filter \u0915\u0930\u0928\u0947 \u0915\u0947 \u0932\u093f\u090f Where \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930\u0924\u0947 \u0939\u0948\u0902 \u0964 <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">SELECT cust_nm, sum(qty) as tot_qty \nFROM `citemmst` \ngroup by cust_nm \nhaving tot_qty > 5<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"148\" height=\"89\" src=\"https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2022\/09\/image-2.png?resize=148%2C89&#038;ssl=1\" alt=\"\" class=\"wp-image-9017\"\/><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">&#8220;Having&#8221; works the same as &#8220;Where&#8221; without an aggregate<\/h2>\n\n\n\n<p>\u092f\u0926\u093f \u0906\u092a Without Aggregate \u0915\u0947 having \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930\u0947\u0902\u0917\u0947 \u0924\u092c \u092f\u0939 Where \u091c\u0948\u0938\u0947 \u0939\u0940 \u0915\u093e\u0930\u094d\u092f \u0915\u0930\u0947\u0917\u093e \u0964<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">SELECT cust_nm, item_nm, qty, rate FROM citemmst having qty > 5; \/\/Both are Same\nSELECT cust_nm, item_nm, qty, rate FROM citemmst WHERE qty > 5;<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"134\" src=\"https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2022\/09\/image-3.png?resize=640%2C134&#038;ssl=1\" alt=\"\" class=\"wp-image-9019\" srcset=\"https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2022\/09\/image-3.png?w=814&amp;ssl=1 814w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2022\/09\/image-3.png?resize=300%2C63&amp;ssl=1 300w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2022\/09\/image-3.png?resize=768%2C160&amp;ssl=1 768w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2022\/09\/image-3.png?resize=150%2C31&amp;ssl=1 150w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Also Apply on Alias Columns <\/h2>\n\n\n\n<p>Having \u0915\u094b \u092d\u0940 Alias Column \u092a\u0930 \u0932\u093f\u0916 \u0938\u0915\u0924\u0947 \u0939\u0948\u0902 \u092f\u093e\u0928\u093f \u0915\u0940 \u092f\u0939 \u0915\u093e\u0930\u094d\u092f Alias \u092f\u093e\u0928\u093f Short Name \u092a\u0930 \u092d\u0940 \u091a\u0932\u0924\u093e \u0939\u0948\u0902\u0964 \u091c\u0948\u0938\u0947 \u0915\u0940 \u0928\u093f\u092e\u094d\u0928 Example \u092e\u0947 tot_qty column alias \u0915\u0947 \u0926\u094d\u0935\u093e\u0930\u093e \u092c\u0928\u093e \u0939\u0948\u0902\u0964 \u0914\u0930 \u0939\u092e \u0909\u0938 \u092a\u0930 \u092d\u0940 having \u0938\u0947 Condition \u0932\u0917\u093e \u092a\u093e \u0930\u0939\u0947 \u0939\u0948\u0902\u0964 <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">SELECT sum(qty) as tot_qty FROM `citemmst` having tot_qty > 0<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><a href=\"https:\/\/selfimagination.in\/tips\/mysql-aggregate-function-in-hindi\/\">MySQL Aggregate Function \u0915\u0947 \u092c\u093e\u0930\u0947 \u092e\u0947 \u091c\u093e\u0928\u0928\u0947 \u0915\u0947 \u0932\u093f\u090f \u0915\u094d\u0932\u093f\u0915 \u0915\u0930\u0947 <\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/selfimagination.in\/tips\/mysql-overview-in-hindi\/\">MySQL Overview <\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Having : Aggregate Function \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930 \u0939\u092e \u0915\u093f\u0938 \u092d\u0940 Table \u0915\u0947 Data \u0915\u094b Group \u0915\u0930\u0924\u0947 \u0939\u0948\u0902 \u092f\u093e\u0928\u093f \u0915\u0940 Count, Sum, Avg, Min, Max \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930 Data \u0915\u094b Summerize \u0915\u0930 \u0932\u0947\u0924\u0947 \u0939\u0948\u0902 \u0964 \u092f\u0926\u093f summerize data \u092a\u0930 \u0939\u092e\u0947 \u0915\u094b\u0908 Filter \u0932\u0917\u093e\u0928\u093e \u0939\u094b \u0924\u092c \u0939\u092e Having \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930\u0924\u0947 \u0939\u0948\u0902 \u0964 \u091c\u0948\u0938\u093e \u0939\u092e Row \u0915\u094b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":9022,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-8996","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mysql"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2022\/09\/mysql-having.jpg?fit=1200%2C628&ssl=1","_links":{"self":[{"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/posts\/8996","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/comments?post=8996"}],"version-history":[{"count":24,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/posts\/8996\/revisions"}],"predecessor-version":[{"id":9025,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/posts\/8996\/revisions\/9025"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/media\/9022"}],"wp:attachment":[{"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/media?parent=8996"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/categories?post=8996"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/tags?post=8996"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}