The HAVING clause is optional and eliminates group rows that do not satisfy a given condition. HAVING is similar to the WHERE clause, but WHERE occurs before the grouping, and HAVING occurs after.
This means that the WHERE clause places conditions on selected columns, whereas the HAVING clause places conditions on groups created by the GROUP BY clause.Here’s an example showing the position of the HAVING clause in a SELECT query:
SELECT column1, column2FROM table1, table2WHERE [ conditions ]GROUP BY column1, column2HAVING [ conditions ]ORDER BY column1, column2
Basic HAVING clause example:
-- compute the average salary per department per job_title-- filtering the result set only to include the departments and job titles with an average salary of at least $50,000SELECT department, job_title, AVG(salary)FROM employeesGROUP BY department, job_titleHAVING AVG(salary) >= 50000;
This query results in a table with columns for department, job title, and average salary. Each row represents the average salary for a unique combination of department and job title, and only those groups with an average salary of at least $50,000 are returned.
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"RisingWave","colors":{"primary":"#005eec","light":"#005eec","dark":"#005eec"},"logo":{"light":"https://mintcdn.com/risingwavelabs/MBiw07hESa08PLsp/logo/light.svg?fit=max\u0026auto=format\u0026n=MBiw07hESa08PLsp\u0026q=85\u0026s=ec9c31744f8c3ddaa5c37f6f7fd0385b","dark":"https://mintcdn.com/risingwavelabs/MBiw07hESa08PLsp/logo/dark.svg?fit=max\u0026auto=format\u0026n=MBiw07hESa08PLsp\u0026q=85\u0026s=5faa0cc3c55a9407df9bb353ee579e89","href":"https://risingwave.com/"},"favicon":"https://mintcdn.com/risingwavelabs/eqqtg34aUutkXCuz/favicon.png?fit=max\u0026auto=format\u0026n=eqqtg34aUutkXCuz\u0026q=85\u0026s=32d724d78a6ff3342f31bed536427c8f","background":{"decoration":"gradient"},"navbar":{"links":[{"href":"https://risingwave.com/resources/?filter=blogs","label":"Blog"}],"primary":{"type":"button","label":"Sign up free","href":"https://cta-service-cms2.hubspot.com/web-interactives/public/v1/track/redirect?encryptedPayload=AVxigLIVNzabNcOPWI6bnbgE5v5wBhWy6pk6dNZ0jpoHYTJVXYdKJ2sN2%2Bz81tvbqU9obUFnA6qJBV3VfxEI3LOXQz%2FR1xANlR5nhw9CzFWt250u2%2B%2FfsHip8lVRCRiV%2FX0l10HpM%2BZWdr%2FmPAe%2BTHYRotiKZ1nJ494JNXcirwOZXbhlh5RTBgXXdxwxHyst\u0026webInteractiveContentId=183953770777\u0026portalId=24308934"}},"footer":{"socials":{"github":"https://github.com/risingwavelabs/risingwave","x":"https://go.risingwave.com/twitter","linkedin":"https://go.risingwave.com/linkedin","slack":"https://go.risingwave.com/slack","youtube":"https://go.risingwave.com/youtube"}},"fonts":{"heading":{"family":"Inter","format":"woff2"},"body":{"family":"Inter","format":"woff2"}},"integrations":{"ga4":{"measurementId":"G-VG98SVDEYE"},"gtm":{"tagId":"GTM-WT9WLCBX"}},"contextual":{"options":["copy","view","chatgpt","claude"],"display":"header"},"styling":{"latex":true},"navigation":{"global":{"anchors":[{"anchor":"Join Slack community","icon":"slack","href":"https://go.risingwave.com/slack"},{"anchor":"GitHub","icon":"github","href":"https://github.com/risingwavelabs/risingwave"}]},"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"risingwavelabs","hasAudioNarration":false,"actualSubdomain":"risingwavelabs","customDomains":["docs.risingwave.com"],"gitSource":{"type":"github","owner":"risingwavelabs","repo":"risingwave-docs","deployBranch":"main","contentDirectory":"","isPrivate":false,"mountPath":"","label":""},"chroma":{"liveDeploymentHistoryId":"6ae9a815bc952f34b9c019d1","collectionId":"2ac1ac98-bdb0-4e02-9313-32f1302fd4af","schemaVersion":"v3","latestBuiltDeploymentHistoryId":"6ae9a815bc952f34b9c019d1"},"feedback":{"thumbs":true,"edits":true,"issues":true},"entitlements":{"AI_CHAT":{"status":"ENABLED"},"WEB_MCP":{"status":"ENABLED"},"NARRATION":{"status":"ENABLED"}},"buildId":"6ae9a815bc952f34b9c019d1","clientVersion":"0.0.4045","searchFilterCounts":[{"language":"default","tag":"Guides","count":279},{"language":"default","tag":"SQL/Python/UDFs","count":156},{"language":"default","tag":"SQL reference","count":148},{"language":"default","tag":"Work with data","count":117},{"language":"default","tag":"Commands","count":99},{"language":"default","tag":"Cloud","count":67},{"language":"default","tag":"Ingest data","count":52},{"language":"default","tag":"Apache Iceberg™","count":37},{"language":"default","tag":"Deliver data","count":35},{"language":"default","tag":"Install \u0026 Operate","count":32}]},"assistantConfig":{},"basePath":"","hasChatPermissions":true,"hasWebMcpPermissions":true,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"byok-sep-25","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"vite-origin","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-updated-9-15","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"sso-setup-deadline-banner","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":false},"customCss":[{"filePath":"styles.css","content":"@font-face{font-family:'Monument Grotesk';src:url(https://fonts.gstatic.com/s/inter/v18/UcCo3FwrK3iLTcviYwYZ8UA3.woff2);font-weight:400;font-style:normal;font-display:swap}h1,h2,h3{font-family:'monument grotesk';letter-spacing:normal!important}"}],"page":{"pagePath":"sql/query-syntax/having-clause","slug":"/sql/query-syntax/having-clause","pageMetadata":{"title":"HAVING clause","description":"The `HAVING` clause is optional and eliminates group rows that do not satisfy a given condition. `HAVING` is similar to the `WHERE` clause, but `WHERE` occurs before the grouping, and `HAVING` occurs after.","href":"/sql/query-syntax/having-clause"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx, jsxs: _jsxs} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n code: \"code\",\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsxs(_components.p, {\n children: [\"The \", _jsx(_components.code, {\n children: \"HAVING\"\n }), \" clause is optional and eliminates group rows that do not satisfy a given condition. \", _jsx(_components.code, {\n children: \"HAVING\"\n }), \" is similar to the \", _jsx(_components.code, {\n children: \"WHERE\"\n }), \" clause, but \", _jsx(_components.code, {\n children: \"WHERE\"\n }), \" occurs before the grouping, and \", _jsx(_components.code, {\n children: \"HAVING\"\n }), \" occurs after.\"]\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={code:`code`,p:`p`,pre:`pre`,span:`span`,..._provideComponents(),...props.components},{CodeBlock}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[`This means that the `,_jsx(_components.code,{children:`WHERE`}),` clause places conditions on selected columns, whereas the `,_jsx(_components.code,{children:`HAVING`}),` clause places conditions on groups created by the `,_jsx(_components.code,{children:`GROUP BY`}),` clause.`]}),`\n`,_jsxs(_components.p,{children:[`Here’s an example showing the position of the `,_jsx(_components.code,{children:`HAVING`}),` clause in a SELECT query:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`6`,language:`sql`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`sql`,children:_jsxs(_components.code,{language:`sql`,numberOfLines:`6`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`SELECT`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` column1, column2`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`FROM`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` table1, table2`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`WHERE`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [ conditions ]`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`GROUP BY`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` column1, column2`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`HAVING`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [ conditions ]`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`ORDER BY`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` column1, column2`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`Basic `,_jsx(_components.code,{children:`HAVING`}),` clause example:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`6`,language:`sql`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`sql`,children:_jsxs(_components.code,{language:`sql`,numberOfLines:`6`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`-- compute the average salary per department per job_title`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`-- filtering the result set only to include the departments and job titles with an average salary of at least $50,000`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`SELECT`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` department, job_title, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`AVG`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(salary)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`FROM`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` employees`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`GROUP BY`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` department, job_title`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`HAVING`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` AVG`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(salary) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`>=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 50000`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`This query results in a table with columns for department, job title, and average salary. Each row represents the average salary for a unique combination of department and job title, and only those groups with an average salary of at least $50,000 are returned.`})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"HAVING clause","description":"The `HAVING` clause is optional and eliminates group rows that do not satisfy a given condition. `HAVING` is similar to the `WHERE` clause, but `WHERE` occurs before the grouping, and `HAVING` occurs after.","href":"/sql/query-syntax/having-clause"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[],"codeExamples":{}},"jsLinks":[],"subdomain":"risingwavelabs","siteName":"RisingWave","title":"HAVING clause - RisingWave","navMaps":{"firstHrefInVersion":{"Current (v3.0)":{"href":"/sql/query-syntax/having-clause","matchLevel":0}},"firstHrefInLanguage":{}},"lastModified":"2026-01-22T08:22:17.546Z","originalFileLocation":"sql/query-syntax/having-clause.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"The HAVING clause is optional and eliminates group rows that do not satisfy a given condition. HAVING is similar to the WHERE clause, but WHERE occurs before the grouping, and HAVING occurs after.\">\u003cmeta data-mint-head name=\"application-name\" content=\"RisingWave\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/risingwavelabs/XB2VPvZUQ1sTe2fS/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/risingwavelabs/XB2VPvZUQ1sTe2fS/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/risingwavelabs/XB2VPvZUQ1sTe2fS/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/risingwavelabs/XB2VPvZUQ1sTe2fS/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/risingwavelabs/XB2VPvZUQ1sTe2fS/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/risingwavelabs/XB2VPvZUQ1sTe2fS/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/risingwavelabs/XB2VPvZUQ1sTe2fS/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/risingwavelabs/XB2VPvZUQ1sTe2fS/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/risingwavelabs/XB2VPvZUQ1sTe2fS/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"HAVING clause - RisingWave\">\u003cmeta data-mint-head property=\"og:description\" content=\"The HAVING clause is optional and eliminates group rows that do not satisfy a given condition. HAVING is similar to the WHERE clause, but WHERE occurs before the grouping, and HAVING occurs after.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"RisingWave\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.risingwave.com/sql/query-syntax/having-clause\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://risingwavelabs.mintlify.app/_mintlify/api/og/v2?division=Query+syntax\u0026amp;title=HAVING+clause\u0026amp;description=The+%60HAVING%60+clause+is+optional+and+eliminates+group+rows+that+do+not+satisfy+a+given+condition.+%60HAVING%60+is+similar+to+the+%60WHERE%60+clause%2C+but+%60WHERE%60+occurs+b\u0026amp;theme=f623197ed300707840b7cb4e\u0026amp;signature=c7ff66a6c5ec9a12616e30ce140cf009fd6d701a84c11c92b4e9466ca49e83ab\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"HAVING clause - RisingWave\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"The HAVING clause is optional and eliminates group rows that do not satisfy a given condition. HAVING is similar to the WHERE clause, but WHERE occurs before the grouping, and HAVING occurs after.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://risingwavelabs.mintlify.app/_mintlify/api/og/v2?division=Query+syntax\u0026amp;title=HAVING+clause\u0026amp;description=The+%60HAVING%60+clause+is+optional+and+eliminates+group+rows+that+do+not+satisfy+a+given+condition.+%60HAVING%60+is+similar+to+the+%60WHERE%60+clause%2C+but+%60WHERE%60+occurs+b\u0026amp;theme=f623197ed300707840b7cb4e\u0026amp;signature=c7ff66a6c5ec9a12616e30ce140cf009fd6d701a84c11c92b4e9466ca49e83ab\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/risingwavelabs/XB2VPvZUQ1sTe2fS/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"RisingWave\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#005eec\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.risingwave.com/sql/query-syntax/having-clause\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/sql/query-syntax/having-clause.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.risingwave.com/#organization\",\"name\":\"RisingWave\",\"url\":\"https://docs.risingwave.com\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/risingwavelabs/MBiw07hESa08PLsp/logo/light.svg?fit=max\u0026auto=format\u0026n=MBiw07hESa08PLsp\u0026q=85\u0026s=ec9c31744f8c3ddaa5c37f6f7fd0385b\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.risingwave.com#website\",\"name\":\"RisingWave\",\"url\":\"https://docs.risingwave.com\",\"publisher\":{\"@id\":\"https://docs.risingwave.com/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.risingwave.com/sql/query-syntax/having-clause#webpage\",\"url\":\"https://docs.risingwave.com/sql/query-syntax/having-clause\",\"name\":\"HAVING clause\",\"description\":\"The HAVING clause is optional and eliminates group rows that do not satisfy a given condition. HAVING is similar to the WHERE clause, but WHERE occurs before the grouping, and HAVING occurs after.\",\"dateModified\":\"2026-01-22T08:22:17.546Z\",\"isPartOf\":{\"@id\":\"https://docs.risingwave.com#website\"},\"breadcrumb\":{\"@id\":\"https://docs.risingwave.com/sql/query-syntax/having-clause#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.risingwave.com/sql/query-syntax/having-clause#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"SQL reference\",\"item\":\"https://docs.risingwave.com/sql/overview\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Query syntax\",\"item\":\"https://docs.risingwave.com/sql/query-syntax/overview\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"HAVING clause\",\"item\":\"https://docs.risingwave.com/sql/query-syntax/having-clause\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://docs.risingwave.com/sql/query-syntax/having-clause#article\",\"headline\":\"HAVING clause\",\"name\":\"HAVING clause\",\"description\":\"The HAVING clause is optional and eliminates group rows that do not satisfy a given condition. HAVING is similar to the WHERE clause, but WHERE occurs before the grouping, and HAVING occurs after.\",\"url\":\"https://docs.risingwave.com/sql/query-syntax/having-clause\",\"mainEntityOfPage\":{\"@id\":\"https://docs.risingwave.com/sql/query-syntax/having-clause#webpage\"},\"dateModified\":\"2026-01-22T08:22:17.546Z\",\"publisher\":{\"@id\":\"https://docs.risingwave.com/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.risingwave.com#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"RisingWave\",\"creator\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","siteName":"RisingWave","nav":{"global":{"anchors":[{"anchor":"Join Slack community","icon":"slack","href":"https://go.risingwave.com/slack"},{"anchor":"GitHub","icon":"github","href":"https://github.com/risingwavelabs/risingwave"}]},"versions":[{"version":"Current (v3.0)","tabs":[{"tab":"Guides","pages":[{"title":"Guides","href":"/get-started/intro"}]},{"tab":"Apache Iceberg™","pages":[{"title":"Apache Iceberg™","href":"/iceberg/overview"}]},{"tab":"SQL/Python/UDFs","groups":[{"group":"SQL reference","pages":[{"title":"SQL reference","sidebarTitle":"Overview","mode":"wide","href":"/sql/overview"},{"group":"Commands","pages":[{"title":"SQL commands","mode":"wide","sidebarTitle":"Overview","href":"/sql/commands/overview"},{"title":"ALTER CONNECTION","href":"/sql/commands/sql-alter-connection"},{"title":"ALTER DEFAULT PRIVILEGES","href":"/sql/commands/sql-alter-default-privileges"},{"title":"ALTER DATABASE","href":"/sql/commands/sql-alter-database"},{"title":"ALTER FRAGMENT","sidebarTitle":"ALTER FRAGMENT","href":"/sql/commands/sql-alter-fragment"},{"title":"ALTER FUNCTION","href":"/sql/commands/sql-alter-function"},{"title":"ALTER INDEX","href":"/sql/commands/sql-alter-index"},{"title":"ALTER MATERIALIZED VIEW","href":"/sql/commands/sql-alter-materialized-view"},{"title":"ALTER SCHEMA","href":"/sql/commands/sql-alter-schema"},{"title":"ALTER SECRET","href":"/sql/commands/sql-alter-secret"},{"title":"ALTER SINK","href":"/sql/commands/sql-alter-sink"},{"title":"ALTER SOURCE","href":"/sql/commands/sql-alter-source"},{"title":"ALTER SUBSCRIPTION","href":"/sql/commands/sql-alter-subscription"},{"title":"ALTER SWAP","href":"/sql/commands/sql-alter-swap"},{"title":"ALTER SYSTEM","href":"/sql/commands/sql-alter-system"},{"title":"ALTER TABLE","href":"/sql/commands/sql-alter-table"},{"title":"ALTER USER","href":"/sql/commands/sql-alter-user"},{"title":"ALTER VIEW","href":"/sql/commands/sql-alter-view"},{"title":"AS CHANGELOG","href":"/sql/commands/sql-as-changelog"},{"title":"BEGIN","href":"/sql/commands/sql-begin"},{"title":"CANCEL JOBS","href":"/sql/commands/sql-cancel-jobs"},{"title":"COMMENT ON","href":"/sql/commands/sql-comment-on"},{"title":"COMMIT","href":"/sql/commands/sql-commit"},{"title":"COPY","href":"/sql/commands/sql-copy"},{"title":"CREATE AGGREGATE","href":"/sql/commands/sql-create-aggregate"},{"title":"CREATE CONNECTION","href":"/sql/commands/sql-create-connection"},{"title":"CREATE DATABASE","href":"/sql/commands/sql-create-database"},{"title":"CREATE FUNCTION","href":"/sql/commands/sql-create-function"},{"title":"CREATE INDEX","href":"/sql/commands/sql-create-index"},{"title":"CREATE MATERIALIZED VIEW","sidebarTitle":"CREATE MATERIALIZED VIEW","href":"/sql/commands/sql-create-mv"},{"title":"CREATE SCHEMA","href":"/sql/commands/sql-create-schema"},{"title":"CREATE SECRET","href":"/sql/commands/sql-create-secret"},{"title":"CREATE SINK INTO","href":"/sql/commands/sql-create-sink-into"},{"title":"CREATE SINK","href":"/sql/commands/sql-create-sink"},{"title":"CREATE SOURCE","href":"/sql/commands/sql-create-source"},{"title":"CREATE TABLE","href":"/sql/commands/sql-create-table"},{"title":"CREATE USER","href":"/sql/commands/sql-create-user"},{"title":"CREATE VIEW","href":"/sql/commands/sql-create-view"},{"title":"DELETE","href":"/sql/commands/sql-delete"},{"title":"DESCRIBE","href":"/sql/commands/sql-describe"},{"title":"DISCARD","href":"/sql/commands/sql-discard"},{"title":"DROP AGGREGATE","href":"/sql/commands/sql-drop-aggregate"},{"title":"DROP CONNECTION","href":"/sql/commands/sql-drop-connection"},{"title":"DROP DATABASE","href":"/sql/commands/sql-drop-database"},{"title":"DROP FUNCTION","href":"/sql/commands/sql-drop-function"},{"title":"DROP INDEX","href":"/sql/commands/sql-drop-index"},{"title":"DROP MATERIALIZED VIEW","href":"/sql/commands/sql-drop-mv"},{"title":"DROP SCHEMA","href":"/sql/commands/sql-drop-schema"},{"title":"DROP SECRET","href":"/sql/commands/sql-drop-secret"},{"title":"DROP SINK","href":"/sql/commands/sql-drop-sink"},{"title":"DROP SOURCE","href":"/sql/commands/sql-drop-source"},{"title":"DROP TABLE","href":"/sql/commands/sql-drop-table"},{"title":"DROP USER","href":"/sql/commands/sql-drop-user"},{"title":"DROP VIEW","href":"/sql/commands/sql-drop-view"},{"title":"EXPLAIN","href":"/sql/commands/sql-explain"},{"title":"EXPLAIN ANALYZE","href":"/sql/commands/sql-explain-analyze"},{"title":"FLUSH","href":"/sql/commands/sql-flush"},{"title":"GRANT","href":"/sql/commands/sql-grant"},{"title":"INSERT","href":"/sql/commands/sql-insert"},{"title":"RECOVER","href":"/sql/commands/sql-recover"},{"title":"REFRESH TABLE","href":"/sql/commands/sql-refresh-table"},{"title":"REPLACE SINK","href":"/sql/commands/sql-replace-sink"},{"title":"REVOKE","href":"/sql/commands/sql-revoke"},{"title":"SELECT","href":"/sql/commands/sql-select"},{"title":"SET BACKGROUND_DDL","href":"/sql/commands/sql-set-background-ddl"},{"title":"SET DML_WAIT_PERSISTENCE","href":"/sql/commands/sql-set-dml-wait-persistence"},{"title":"SET RW_IMPLICIT_FLUSH","href":"/sql/commands/sql-set-rw-implicit-flush"},{"title":"SET TIME ZONE","href":"/sql/commands/sql-set-time-zone"},{"title":"SET","href":"/sql/commands/sql-set"},{"title":"SHOW CLUSTER","href":"/sql/commands/sql-show-cluster"},{"title":"SHOW COLUMNS","href":"/sql/commands/sql-show-columns"},{"title":"SHOW CONNECTIONS","href":"/sql/commands/sql-show-connections"},{"title":"SHOW CREATE INDEX","href":"/sql/commands/sql-show-create-index"},{"title":"SHOW CREATE MATERIALIZED VIEW","href":"/sql/commands/sql-show-create-mv"},{"title":"SHOW CREATE SINK","href":"/sql/commands/sql-show-create-sink"},{"title":"SHOW CREATE SOURCE","href":"/sql/commands/sql-show-create-source"},{"title":"SHOW CREATE TABLE","href":"/sql/commands/sql-show-create-table"},{"title":"SHOW CREATE VIEW","href":"/sql/commands/sql-show-create-view"},{"title":"SHOW CURSORS","href":"/sql/commands/sql-show-cursors"},{"title":"SHOW DATABASES","href":"/sql/commands/sql-show-databases"},{"title":"SHOW FUNCTIONS","href":"/sql/commands/sql-show-functions"},{"title":"SHOW INDEXES","href":"/sql/commands/sql-show-indexes"},{"title":"SHOW INTERNAL TABLES","href":"/sql/commands/sql-show-internal-tables"},{"title":"SHOW JOBS","href":"/sql/commands/sql-show-jobs"},{"title":"SHOW MATERIALIZED VIEWS","href":"/sql/commands/sql-show-mv"},{"title":"SHOW PARAMETERS","href":"/sql/commands/sql-show-parameters"},{"title":"SHOW PROCESSLIST","href":"/sql/commands/sql-show-processlist"},{"title":"SHOW SCHEMAS","href":"/sql/commands/sql-show-schemas"},{"title":"SHOW SECRETS","href":"/sql/commands/sql-show-secrets"},{"title":"SHOW SINKS","href":"/sql/commands/sql-show-sinks"},{"title":"SHOW SOURCES","href":"/sql/commands/sql-show-sources"},{"title":"SHOW SUBSCRIPTIONS","href":"/sql/commands/sql-show-subscriptions"},{"title":"SHOW SUBSCRIPTION CURSORS","href":"/sql/commands/sql-show-subscription-cursors"},{"title":"SHOW TABLES","href":"/sql/commands/sql-show-tables"},{"title":"SHOW VIEWS","href":"/sql/commands/sql-show-views"},{"title":"START TRANSACTION","href":"/sql/commands/sql-start-transaction"},{"title":"UPDATE","href":"/sql/commands/sql-update"},{"title":"VACUUM","href":"/sql/commands/sql-vacuum"},{"title":"WAIT","href":"/sql/commands/sql-wait"}]},{"group":"Query syntax","pages":[{"title":"Query syntax","sidebarTitle":"Overview","href":"/sql/query-syntax/overview"},{"title":"Literals","href":"/sql/query-syntax/literals"},{"title":"Value expressions","href":"/sql/query-syntax/value-exp"},{"title":"Generated columns","href":"/sql/query-syntax/generated-columns"},{"title":"FROM clause","href":"/sql/query-syntax/from-clause"},{"title":"WHERE clause","href":"/sql/query-syntax/where-clause"},{"title":"GROUP BY clause","description":"The `GROUP BY` clause groups rows in a table with identical data, thus eliminating redundancy in the output and aggregates that apply to these groups.","href":"/sql/query-syntax/group-by-clause"},{"title":"HAVING clause","href":"/sql/query-syntax/having-clause"},{"title":"ORDER BY clause","description":"Use the `ORDER BY` clause to sort the result set of a query based on one or more columns in ascending or descending order. It is commonly used to organize data in a specific sequence for better analysis and presentation.","href":"/sql/query-syntax/order-by-clause"},{"title":"LIMIT clause","mode":"wide","href":"/sql/query-syntax/limit-clause"},{"title":"VALUES clause","href":"/sql/query-syntax/values-clause"},{"title":"Set operations","href":"/sql/query-syntax/set-operations"},{"title":"WITH clause","href":"/sql/query-syntax/with-clause"},{"title":"WITH ORDINALITY clause","href":"/sql/query-syntax/with-ordinality-clause"}]},{"group":"Data types","pages":[{"title":"Overview of data types","sidebarTitle":"Overview","href":"/sql/data-types/overview"},{"title":"Casting","mode":"wide","href":"/sql/data-types/casting"},{"title":"Struct","href":"/sql/data-types/struct"},{"title":"ARRAY type","sidebarTitle":"Array","href":"/sql/data-types/array-type"},{"title":"Map type","sidebarTitle":"Map","href":"/sql/data-types/map-type"},{"title":"JSONB","href":"/sql/data-types/jsonb"},{"title":"VARIANT","href":"/sql/data-types/variant"},{"title":"rw_int256","href":"/sql/data-types/rw-int256"},{"title":"Vector data type","sidebarTitle":"Vector","href":"/sql/data-types/vector"},{"title":"Supported protobuf types","sidebarTitle":"Protobuf","href":"/sql/data-types/supported-protobuf-types"}]},{"group":"Functions and operators","pages":[{"title":"SQL functions and operators","sidebarTitle":"Overview","mode":"wide","href":"/sql/functions/overview"},{"title":"Logical operators","mode":"wide","href":"/sql/functions/logical"},{"title":"Comparison functions and operators","href":"/sql/functions/comparison"},{"title":"Mathematical functions and operators","href":"/sql/functions/mathematical"},{"title":"String functions and operators","href":"/sql/functions/string"},{"title":"Binary string functions and operators","href":"/sql/functions/binarystring"},{"title":"Date and time functions and operators","href":"/sql/functions/datetime"},{"title":"Cryptographic functions","href":"/sql/functions/cryptographic"},{"title":"JSON functions and operators","href":"/sql/functions/json"},{"title":"Array functions and operators","href":"/sql/functions/array"},{"title":"Map functions and operators","href":"/sql/functions/map"},{"title":"Conditional expressions","href":"/sql/functions/conditional"},{"title":"Aggregate functions","href":"/sql/functions/aggregate"},{"title":"Window functions","href":"/sql/functions/window-functions"},{"title":"Set-returning functions","href":"/sql/functions/set-returning"},{"title":"System administration functions","href":"/sql/functions/sys-admin"},{"title":"System information functions","href":"/sql/functions/sys-info"},{"title":"AI functions","href":"/sql/functions/ai"}]},{"title":"Identifiers","href":"/sql/identifiers"},{"group":"System catalogs","pages":[{"title":"System catalogs","sidebarTitle":"Overview","mode":"wide","href":"/sql/system-catalogs/overview"},{"title":"Information schema","href":"/sql/system-catalogs/information-schema"},{"title":"PostgreSQL catalogs","href":"/sql/system-catalogs/pg-catalog"},{"title":"RisingWave catalogs","href":"/sql/system-catalogs/rw-catalog"}]},{"title":"Psql commands","mode":"wide","href":"/sql/psql-commands"}]},{"group":"Python SDK","pages":[{"title":"Python SDK","href":"/sql/python-sdk/intro"}]},{"group":"User-defined functions","pages":[{"title":"User-defined functions","sidebarTitle":"Overview","href":"/sql/udfs/user-defined-functions"},{"group":"External UDFs","pages":[{"title":"External Python UDFs","sidebarTitle":"Python","href":"/sql/udfs/use-udfs-in-python"},{"title":"External Java UDFs","sidebarTitle":"Java","href":"/sql/udfs/use-udfs-in-java"}]},{"group":"Embedded UDFs","pages":[{"title":"Embedded Python UDFs","sidebarTitle":"Python","href":"/sql/udfs/embedded-python-udfs"},{"title":"Use UDFs in JavaScript","sidebarTitle":"JavaScript","href":"/sql/udfs/use-udfs-in-javascript"},{"title":"Use UDFs in Rust","sidebarTitle":"Rust","href":"/sql/udfs/use-udfs-in-rust"}]},{"title":"SQL UDFs","href":"/sql/udfs/sql-udfs"}]}]},{"tab":"Client Libraries","pages":[{"title":"Client Libraries","href":"/client-libraries/overview"}]},{"tab":"Web UI","pages":[{"title":"Web UI","href":"/web-ui/introduction"}]},{"tab":"Changelog","pages":[{"title":"Changelog","href":"/changelog/release-notes"}]}]}]},"basePath":"","title":"HAVING clause - RisingWave","buildId":"dpl_36EDyZCDfRuoUD9af5CH4M1bqY2h","deploymentId":"dpl_36EDyZCDfRuoUD9af5CH4M1bqY2h","dynamics":[],"chunks":[]}