{"id":23645,"date":"2025-07-25T13:29:08","date_gmt":"2025-07-25T13:29:08","guid":{"rendered":"https:\/\/crocoblock.com\/knowledge-base\/?post_type=article&#038;p=23645"},"modified":"2025-07-25T13:29:08","modified_gmt":"2025-07-25T13:29:08","slug":"jetengine-setting-calculated-columns-and-grouping-results-for-sql-queries","status":"publish","type":"article","link":"https:\/\/crocoblock.com\/knowledge-base\/jetengine\/jetengine-setting-calculated-columns-and-grouping-results-for-sql-queries\/","title":{"rendered":"How to Set Calculated Columns and Grouping Results for SQL Query"},"content":{"rendered":"\n<p>With the help of the \u201c<a href=\"https:\/\/crocoblock.com\/knowledge-base\/articles\/jetengine-query-builder-sql-query-type\/\" target=\"_blank\" rel=\"noreferrer noopener\">SQL\/AI Query<\/a>\u201d type of the <em>JetEngine<\/em> plugin, you can create a query with database table values.\u00a0<\/p>\n\n\n\n<p>The <strong>Group Results<\/strong> feature allows you to combine query results by duplicate values in one of the columns. For example, you have columns for users and their corresponding countries. You can group the selection by the column with countries, and then only one user from each country will be displayed by default. If you combine <strong>Group results<\/strong> with the <strong>Calculated Columns<\/strong> feature, you can display a list of countries along with some calculated values for all rows (for example, the country and the number of users from this country in the database).<\/p>\n\n\n\n<p>Another example is counting the number of posts each author has published, which will be described in this tutorial.<\/p>\n\n\n\n<p>To create a new \u201cSQL\/AI Query\u201d, go to <strong><em>WordPress Dashboard &gt; JetEngine &gt; Query Builder<\/em><\/strong> and press the <strong>\u201cAdd New\u201d <\/strong>button.<\/p>\n\n\n\n<p>Give the new query a <strong>Name <\/strong>and<strong> <\/strong>choose \u201cSQL\/AI Query<strong> Query Type<\/strong>.&nbsp;<\/p>\n\n\n\n<p>In the <strong>From table <\/strong>drop-down menu, select an SQL table from which you would like to retrieve the data (\u201cposts\u201d in this case).<\/p>\n\n\n\n<p>Optionally, we press the \u201c<strong>Add new<\/strong>\u201d button in the <strong>Where (query clauses) <\/strong>to set such options:<\/p>\n\n\n\n<ul>\n<li><strong>Column<\/strong> \u2014 \u201cpost_type\u201d;<\/li>\n\n\n\n<li><strong>Compare<\/strong> \u2014 \u201cEqual (=)\u201d;<\/li>\n\n\n\n<li><strong>Value<\/strong> \u2014 \u201cpost\u201d.<\/li>\n<\/ul>\n\n\n\n<p>Such adjustments specify the default WordPress \u201cPosts\u201d post type as the query source.&nbsp;Enable the <strong>Group Results<\/strong> toggle. In the <strong>Group By <\/strong>option,<strong> <\/strong>choose a column by which the results will be grouped (in our example, the \u201cpost_author\u201d option).<\/p>\n\n\n\n<div class=\"wp-block-image size-large\"><a href=\"https:\/\/crocoblock.com\/knowledge-base\/wp-content\/uploads\/2021\/09\/group-query-results-by-a-table-column.webp\"><img loading=\"lazy\" decoding=\"async\" width=\"1824\" height=\"1100\" src=\"https:\/\/crocoblock.com\/knowledge-base\/wp-content\/uploads\/2021\/09\/group-query-results-by-a-table-column.webp\" alt=\"group query results by a table column\" class=\"wp-image-48888\" srcset=\"https:\/\/crocoblock.com\/knowledge-base\/wp-content\/uploads\/2021\/09\/group-query-results-by-a-table-column.webp 1824w, https:\/\/crocoblock.com\/knowledge-base\/wp-content\/uploads\/2021\/09\/group-query-results-by-a-table-column-300x181.webp 300w, https:\/\/crocoblock.com\/knowledge-base\/wp-content\/uploads\/2021\/09\/group-query-results-by-a-table-column-1024x618.webp 1024w, https:\/\/crocoblock.com\/knowledge-base\/wp-content\/uploads\/2021\/09\/group-query-results-by-a-table-column-768x463.webp 768w, https:\/\/crocoblock.com\/knowledge-base\/wp-content\/uploads\/2021\/09\/group-query-results-by-a-table-column-1536x926.webp 1536w, https:\/\/crocoblock.com\/knowledge-base\/wp-content\/uploads\/2021\/09\/group-query-results-by-a-table-column-600x362.webp 600w\" sizes=\"(max-width: 1824px) 100vw, 1824px\" \/><\/a><\/div>\n\n\n\n<p>In the <strong>Include columns <\/strong>drop-down menu, select what columns should be included in the query results (the \u201cpost_author\u201d option in our case).<\/p>\n\n\n\n<p>Then, enable the <strong>Include Calculated Columns <\/strong>toggle and click the <strong>\u201cAdd New\u201d <\/strong>button.<\/p>\n\n\n\n<p>A <strong>Calculated Columns <\/strong>section will appear, which contains such options:<\/p>\n\n\n\n<ul>\n<li><strong>Column <\/strong>\u2014<strong> <\/strong>select a column by which you want to group the results (e.g., \u201cID\u201d);<\/li>\n\n\n\n<li><strong>Function <\/strong>\u2014<strong> <\/strong>pick the function that will be applied to the values of the chosen column (for our case, we choose \u201cCOUNT\u201d):\n<ul>\n<li><strong>COUNT <\/strong>\u2014 this function counts the values of the column;<\/li>\n\n\n\n<li><strong>MAX <\/strong>\u2014 it checks the values and shows the maximum one;<\/li>\n\n\n\n<li><strong>MIN <\/strong>\u2014&nbsp; it checks the values and shows the minimum one;<\/li>\n\n\n\n<li><strong>SUM <\/strong>\u2014 counts the sum of values;<\/li>\n\n\n\n<li><strong>AVG <\/strong>\u2014 counts the average value.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Alias<\/strong> \u2014 set the name under which the column will appear in the results. Avoid using the name of an existing column, as this will override its original value. In our example, it can be \u201call_posts_by_author\u201d.<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-image size-large\"><a href=\"https:\/\/crocoblock.com\/knowledge-base\/wp-content\/uploads\/2021\/09\/include-calculated-columns-settings.webp\"><img loading=\"lazy\" decoding=\"async\" width=\"1824\" height=\"1100\" src=\"https:\/\/crocoblock.com\/knowledge-base\/wp-content\/uploads\/2021\/09\/include-calculated-columns-settings.webp\" alt=\"include calculated columns settings\" class=\"wp-image-48886\" srcset=\"https:\/\/crocoblock.com\/knowledge-base\/wp-content\/uploads\/2021\/09\/include-calculated-columns-settings.webp 1824w, https:\/\/crocoblock.com\/knowledge-base\/wp-content\/uploads\/2021\/09\/include-calculated-columns-settings-300x181.webp 300w, https:\/\/crocoblock.com\/knowledge-base\/wp-content\/uploads\/2021\/09\/include-calculated-columns-settings-1024x618.webp 1024w, https:\/\/crocoblock.com\/knowledge-base\/wp-content\/uploads\/2021\/09\/include-calculated-columns-settings-768x463.webp 768w, https:\/\/crocoblock.com\/knowledge-base\/wp-content\/uploads\/2021\/09\/include-calculated-columns-settings-1536x926.webp 1536w, https:\/\/crocoblock.com\/knowledge-base\/wp-content\/uploads\/2021\/09\/include-calculated-columns-settings-600x362.webp 600w\" sizes=\"(max-width: 1824px) 100vw, 1824px\" \/><\/a><\/div>\n\n\n\n<p>To check the results, scroll up the page and enable the <strong>Preview results <\/strong>toggle.<\/p>\n\n\n\n<p>In our case, the query shows two results (two sites\u2019 authors who published posts), where [post_author] shows the author ID and [all_posts_by_author] shows the post number.<\/p>\n\n\n\n<p>Finally, if the results are satisfactory, save the query by pressing the \u201c<strong>Add\/Update Query<\/strong>\u201d button.<\/p>\n\n\n\n<div class=\"wp-block-image size-large\"><a href=\"https:\/\/crocoblock.com\/knowledge-base\/wp-content\/uploads\/2021\/09\/calculated-columns-and-grouping-results-preview.webp\"><img loading=\"lazy\" decoding=\"async\" width=\"1824\" height=\"1100\" src=\"https:\/\/crocoblock.com\/knowledge-base\/wp-content\/uploads\/2021\/09\/calculated-columns-and-grouping-results-preview.webp\" alt=\"calculated columns and grouping results preview\" class=\"wp-image-48887\" srcset=\"https:\/\/crocoblock.com\/knowledge-base\/wp-content\/uploads\/2021\/09\/calculated-columns-and-grouping-results-preview.webp 1824w, https:\/\/crocoblock.com\/knowledge-base\/wp-content\/uploads\/2021\/09\/calculated-columns-and-grouping-results-preview-300x181.webp 300w, https:\/\/crocoblock.com\/knowledge-base\/wp-content\/uploads\/2021\/09\/calculated-columns-and-grouping-results-preview-1024x618.webp 1024w, https:\/\/crocoblock.com\/knowledge-base\/wp-content\/uploads\/2021\/09\/calculated-columns-and-grouping-results-preview-768x463.webp 768w, https:\/\/crocoblock.com\/knowledge-base\/wp-content\/uploads\/2021\/09\/calculated-columns-and-grouping-results-preview-1536x926.webp 1536w, https:\/\/crocoblock.com\/knowledge-base\/wp-content\/uploads\/2021\/09\/calculated-columns-and-grouping-results-preview-600x362.webp 600w\" sizes=\"(max-width: 1824px) 100vw, 1824px\" \/><\/a><\/div>\n\n\n\n<p>That\u2019s all of setting calculated columns and grouping results for \u201cSQL Query\u201d using the <em>JetEngine<\/em> <strong>Query Builder <\/strong>feature for your WordPress website.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to set calculated columns and grouping results for SQL Queries with JetEngine Query Builder.<\/p>\n","protected":false},"author":8,"featured_media":0,"template":"","format":"standard","builder-category":[],"article-category":[405],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Setting Calculated Columns and Grouping Results \u2014 JetEngine | Crocoblock<\/title>\n<meta name=\"description\" content=\"Combining Group Results with the Calculated Columns feature, allows you to display a list with some calculated values for all rows in JetEngine Elementor.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/crocoblock.com\/knowledge-base\/jetengine\/jetengine-setting-calculated-columns-and-grouping-results-for-sql-queries\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Setting Calculated Columns and Grouping Results \u2014 JetEngine | Crocoblock\" \/>\n<meta property=\"og:description\" content=\"Combining Group Results with the Calculated Columns feature, allows you to display a list with some calculated values for all rows in JetEngine Elementor.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/crocoblock.com\/knowledge-base\/jetengine\/jetengine-setting-calculated-columns-and-grouping-results-for-sql-queries\/\" \/>\n<meta property=\"og:site_name\" content=\"Help Center\" \/>\n<meta property=\"og:image\" content=\"https:\/\/crocoblock.com\/knowledge-base\/wp-content\/uploads\/2021\/09\/group-query-results-by-a-table-column.webp\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/crocoblock.com\/knowledge-base\/jetengine\/jetengine-setting-calculated-columns-and-grouping-results-for-sql-queries\/\",\"url\":\"https:\/\/crocoblock.com\/knowledge-base\/jetengine\/jetengine-setting-calculated-columns-and-grouping-results-for-sql-queries\/\",\"name\":\"Setting Calculated Columns and Grouping Results \u2014 JetEngine | Crocoblock\",\"isPartOf\":{\"@id\":\"https:\/\/crocoblock.com\/knowledge-base\/#website\"},\"datePublished\":\"2025-07-25T13:29:08+00:00\",\"dateModified\":\"2025-07-25T13:29:08+00:00\",\"description\":\"Combining Group Results with the Calculated Columns feature, allows you to display a list with some calculated values for all rows in JetEngine Elementor.\",\"breadcrumb\":{\"@id\":\"https:\/\/crocoblock.com\/knowledge-base\/jetengine\/jetengine-setting-calculated-columns-and-grouping-results-for-sql-queries\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/crocoblock.com\/knowledge-base\/jetengine\/jetengine-setting-calculated-columns-and-grouping-results-for-sql-queries\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/crocoblock.com\/knowledge-base\/jetengine\/jetengine-setting-calculated-columns-and-grouping-results-for-sql-queries\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/crocoblock.com\/knowledge-base\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Articles\",\"item\":\"https:\/\/crocoblock.com\/knowledge-base\/articles\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"How to Set Calculated Columns and Grouping Results for SQL Query\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/crocoblock.com\/knowledge-base\/#website\",\"url\":\"https:\/\/crocoblock.com\/knowledge-base\/\",\"name\":\"Help Center\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/crocoblock.com\/knowledge-base\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/crocoblock.com\/knowledge-base\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/crocoblock.com\/knowledge-base\/#organization\",\"name\":\"Help Center\",\"url\":\"https:\/\/crocoblock.com\/knowledge-base\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/crocoblock.com\/knowledge-base\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/crocoblock.com\/knowledge-base\/wp-content\/uploads\/2025\/04\/invert-crocoblock-logo.svg\",\"contentUrl\":\"https:\/\/crocoblock.com\/knowledge-base\/wp-content\/uploads\/2025\/04\/invert-crocoblock-logo.svg\",\"caption\":\"Help Center\"},\"image\":{\"@id\":\"https:\/\/crocoblock.com\/knowledge-base\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Setting Calculated Columns and Grouping Results \u2014 JetEngine | Crocoblock","description":"Combining Group Results with the Calculated Columns feature, allows you to display a list with some calculated values for all rows in JetEngine Elementor.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/crocoblock.com\/knowledge-base\/jetengine\/jetengine-setting-calculated-columns-and-grouping-results-for-sql-queries\/","og_locale":"en_US","og_type":"article","og_title":"Setting Calculated Columns and Grouping Results \u2014 JetEngine | Crocoblock","og_description":"Combining Group Results with the Calculated Columns feature, allows you to display a list with some calculated values for all rows in JetEngine Elementor.","og_url":"https:\/\/crocoblock.com\/knowledge-base\/jetengine\/jetengine-setting-calculated-columns-and-grouping-results-for-sql-queries\/","og_site_name":"Help Center","og_image":[{"url":"https:\/\/crocoblock.com\/knowledge-base\/wp-content\/uploads\/2021\/09\/group-query-results-by-a-table-column.webp"}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/crocoblock.com\/knowledge-base\/jetengine\/jetengine-setting-calculated-columns-and-grouping-results-for-sql-queries\/","url":"https:\/\/crocoblock.com\/knowledge-base\/jetengine\/jetengine-setting-calculated-columns-and-grouping-results-for-sql-queries\/","name":"Setting Calculated Columns and Grouping Results \u2014 JetEngine | Crocoblock","isPartOf":{"@id":"https:\/\/crocoblock.com\/knowledge-base\/#website"},"datePublished":"2025-07-25T13:29:08+00:00","dateModified":"2025-07-25T13:29:08+00:00","description":"Combining Group Results with the Calculated Columns feature, allows you to display a list with some calculated values for all rows in JetEngine Elementor.","breadcrumb":{"@id":"https:\/\/crocoblock.com\/knowledge-base\/jetengine\/jetengine-setting-calculated-columns-and-grouping-results-for-sql-queries\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/crocoblock.com\/knowledge-base\/jetengine\/jetengine-setting-calculated-columns-and-grouping-results-for-sql-queries\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/crocoblock.com\/knowledge-base\/jetengine\/jetengine-setting-calculated-columns-and-grouping-results-for-sql-queries\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/crocoblock.com\/knowledge-base\/"},{"@type":"ListItem","position":2,"name":"Articles","item":"https:\/\/crocoblock.com\/knowledge-base\/articles\/"},{"@type":"ListItem","position":3,"name":"How to Set Calculated Columns and Grouping Results for SQL Query"}]},{"@type":"WebSite","@id":"https:\/\/crocoblock.com\/knowledge-base\/#website","url":"https:\/\/crocoblock.com\/knowledge-base\/","name":"Help Center","description":"","publisher":{"@id":"https:\/\/crocoblock.com\/knowledge-base\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/crocoblock.com\/knowledge-base\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/crocoblock.com\/knowledge-base\/#organization","name":"Help Center","url":"https:\/\/crocoblock.com\/knowledge-base\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/crocoblock.com\/knowledge-base\/#\/schema\/logo\/image\/","url":"https:\/\/crocoblock.com\/knowledge-base\/wp-content\/uploads\/2025\/04\/invert-crocoblock-logo.svg","contentUrl":"https:\/\/crocoblock.com\/knowledge-base\/wp-content\/uploads\/2025\/04\/invert-crocoblock-logo.svg","caption":"Help Center"},"image":{"@id":"https:\/\/crocoblock.com\/knowledge-base\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/crocoblock.com\/knowledge-base\/wp-json\/wp\/v2\/article\/23645"}],"collection":[{"href":"https:\/\/crocoblock.com\/knowledge-base\/wp-json\/wp\/v2\/article"}],"about":[{"href":"https:\/\/crocoblock.com\/knowledge-base\/wp-json\/wp\/v2\/types\/article"}],"author":[{"embeddable":true,"href":"https:\/\/crocoblock.com\/knowledge-base\/wp-json\/wp\/v2\/users\/8"}],"wp:attachment":[{"href":"https:\/\/crocoblock.com\/knowledge-base\/wp-json\/wp\/v2\/media?parent=23645"}],"wp:term":[{"taxonomy":"builder-category","embeddable":true,"href":"https:\/\/crocoblock.com\/knowledge-base\/wp-json\/wp\/v2\/builder-category?post=23645"},{"taxonomy":"article-category","embeddable":true,"href":"https:\/\/crocoblock.com\/knowledge-base\/wp-json\/wp\/v2\/article-category?post=23645"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}