This is my views configuration
views setting
And output is
views output

I can see the output when logged in. To see the output as anonymous user I set in permission page as " View user information : Anonymous " and got the below error.

The website encountered an unexpected error. Please try again later.</br></br><em class="placeholder">Drupal\Core\Database\DatabaseExceptionWrapper</em>: Exception in No of users[no_of_users]: SQLSTATE[42000]: Syntax error or access violation: 1140 Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause: SELECT users_field_data.uid AS uid, COUNT(user__roles.roles_target_id) AS user__roles_roles_target_id
FROM 
{users_field_data} users_field_data
LEFT JOIN {user__roles} user__roles ON users_field_data.uid = user__roles.entity_id; Array
(
)
 in <em class="placeholder">Drupal\views\Plugin\views\query\Sql-&gt;execute()</em> (line <em class="placeholder">1496</em> of <em class="placeholder">core/modules/views/src/Plugin/views/query/Sql.php</em>). <pre class="backtrace">Drupal\views\ViewExecutable-&gt;execute(NULL) (Line: 1451)
Drupal\views\ViewExecutable-&gt;render() (Line: 117)
Drupal\views\Plugin\views\display\Block-&gt;execute() (Line: 1627)
Drupal\views\ViewExecutable-&gt;executeDisplay(&#039;block_1&#039;, Array) (Line: 77)
Drupal\views\Element\View::preRenderViewElement(Array) (Line: 59)
Drupal\views\Plugin\Block\ViewsBlock-&gt;build() (Line: 203)
Drupal\block\BlockViewBuilder::preRender(Array)
call_user_func(&#039;Drupal\block\BlockViewBuilder::preRender&#039;, Array) (Line: 378)
Drupal\Core\Render\Renderer-&gt;doRender(Array) (Line: 450)
Drupal\Core\Render\Renderer-&gt;doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer-&gt;render(Array) (Line: 490)
Drupal\Core\Template\TwigExtension-&gt;escapeFilter(Object, Array, &#039;html&#039;, NULL, 1) (Line: 340)
__TwigTemplate_4a80d2e940672d7ecd680f8b0a6d32e7ae7f79a8c4ad5a379b2fdd15200feed9-&gt;block_footer(Array, Array) (Line: 215)
Twig_Template-&gt;displayBlock(&#039;footer&#039;, Array, Array) (Line: 90)
__TwigTemplate_4a80d2e940672d7ecd680f8b0a6d32e7ae7f79a8c4ad5a379b2fdd15200feed9-&gt;doDisplay(Array, Array) (Line: 432)
Twig_Template-&gt;displayWithErrorHandling(Array, Array) (Line: 403)
Twig_Template-&gt;display(Array) (Line: 411)
Twig_Template-&gt;render(Array) (Line: 64)
twig_render_template(&#039;themes/qgm/templates/system/page.html.twig&#039;, Array) (Line: 384)
Drupal\Core\Theme\ThemeManager-&gt;render(&#039;page&#039;, Array) (Line: 437)
Drupal\Core\Render\Renderer-&gt;doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer-&gt;render(Array) (Line: 490)
Drupal\Core\Template\TwigExtension-&gt;escapeFilter(Object, Array, &#039;html&#039;, NULL, 1) (Line: 90)
__TwigTemplate_e1a9dbb34caa1c133cb544a7069db1587b57988d97401f143244d11a5c570367-&gt;doDisplay(Array, Array) (Line: 432)
Twig_Template-&gt;displayWithErrorHandling(Array, Array) (Line: 403)
Twig_Template-&gt;display(Array) (Line: 411)
Twig_Template-&gt;render(Array) (Line: 64)
twig_render_template(&#039;themes/bootstrap/templates/system/html.html.twig&#039;, Array) (Line: 384)
Drupal\Core\Theme\ThemeManager-&gt;render(&#039;html&#039;, Array) (Line: 437)
Drupal\Core\Render\Renderer-&gt;doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer-&gt;render(Array) (Line: 147)
Drupal\Core\Render\MainContent\HtmlRenderer-&gt;Drupal\Core\Render\MainContent\{closure}() (Line: 582)
Drupal\Core\Render\Renderer-&gt;executeInRenderContext(Object, Object) (Line: 148)
Drupal\Core\Render\MainContent\HtmlRenderer-&gt;renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber-&gt;onViewRenderArray(Object, &#039;kernel.view&#039;, Object) (Line: 108)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher-&gt;dispatch(&#039;kernel.view&#039;, Object) (Line: 158)
Symfony\Component\HttpKernel\HttpKernel-&gt;handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel-&gt;handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session-&gt;handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle-&gt;handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache-&gt;pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache-&gt;handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware-&gt;handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware-&gt;handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel-&gt;handle(Object, 1, 1) (Line: 657)
Drupal\Core\DrupalKernel-&gt;handle(Object) (Line: 19)
</pre>
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dbjpanda created an issue. See original summary.

dbjpanda’s picture

Project: Views (for Drupal 7) » Drupal core
Version: 8.x-3.x-dev » 8.4.x-dev
Component: Code » views.module
Dubs’s picture

I had the same issue. To work around you can add an aggregated field that groups together and will always have the same value, e.g. User Entity Type, and then hide that field. This will add the GROUP BY clause to your view.

I realise this isn't a fix, but it should make the view display what you need.

smokris’s picture

Steps to reproduce the error on a fresh Drupal 8 site (tested with Drupal 8.5.2, PHP 7.1.15, and MySQL 5.6.37):

  • Create a new content type and add a Number (Integer) field
  • Create a View showing Content of the newly-created content type, unsorted, then enable aggregation and add the number field to the view, with aggregation type Count, and remove the Title field

It generates this query:

SELECT node_field_data.nid AS nid, COUNT(node__field_test.field_test_value) AS node__field_test_field_test_value, COUNT(node__field_test.delta) AS node__field_test_delta, COUNT(node__field_test.langcode) AS node__field_test_langcode, COUNT(node__field_test.bundle) AS node__field_test_bundle
FROM 
{node_field_data} node_field_data
LEFT JOIN {node__field_test} node__field_test ON node_field_data.nid = node__field_test.entity_id AND node__field_test.deleted = '0'
WHERE (node_field_data.status = '1') AND (node_field_data.type IN ('test'))
LIMIT 11 OFFSET 0

…which results in this error:

Syntax error or access violation: 1140 Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause
sic’s picture

same error when counting webform submissions on entity id filter

gustavo.contreras’s picture

Good morning, I have the same error, in a clean installation of Drupal 8.6.10 without contributed modules, when I'm going to agregate a numeric field.

jukka792’s picture

Same error trying to count the amount of nodes with aggregation.
Drupal 8.8.5

mmbdomi’s picture

Having the same issue, any solution ?

brulain’s picture

+1

mmbdomi’s picture

Hello,

I got this working by grouping by the right field.

Every other time I was grouping by with the wrong field, that is why the issue was occurring, you need to make sure that you are grouping by the right fields.

mmbdomi’s picture

There are 3 images that are not related to my comment (group-by.jpg only related one), I do not know how they got attached, can someone remove them then remove this comment ?

thank you

Version: 8.4.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Branches prior to 8.8.x are not supported, and Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.