How to fix my SQL Group By issue? I have a problem with MySql request on Drupal 8.
I want to translate this request to Drupal:

SELECT x.camp AS camp, x.code AS espece, y.des AS designation, x.pf AS pf,
ROUND( SUM( x.pn - x.qte ) , 3 ) AS qte
FROM apport.apport x, apport.cereale y, apport.operation z
WHERE x.code = y.code
AND x.ope = z.code
GROUP BY x.camp, x.code
ORDER BY x.camp, x.code


This request works on PhpMyAdmin.

So, I do this:

    $query = $db-&gt;select('apport.apport','x');
    $query-&gt;join('apport.cereale','y', 'x.code = y.code');
    $query-&gt;join('apport.operation','z', 'x.ope = z.code');

    $query-&gt;fields('x', array('camp', 'code' ,'pf'));
    $query-&gt;fields('y', array('des'));

    $query-&gt;addExpression('ROUND(SUM(x.pn-x.qte),3)','qte');
    $query-&gt;groupBy('x.camp')-&gt;groupBy('x.code');
    $query-&gt;orderBy('x.camp','ASC')-&gt;orderBy('x.code','ASC');

    $result = $query-&gt;execute();

    $tableau = array();

    foreach ($result as $record) {
        $row['camp'] = $record-&gt;camp;
        $row['code'] = $record-&gt;code;
        $row['des'] = $record-&gt;des;
        $row['pf'] = $record-&gt;pf;
        $row['qte'] = $record-&gt;qte;

        $tableau[] = $row;

        print_r($tableau);
    }


But it doesn't work. The problem comes probably from here:

    $query-&gt;addExpression('ROUND(SUM(x.pn-x.qte),3)','qte');
    $query-&gt;groupBy('x.camp')-&gt;groupBy('x.code');


Because when I comment the above two lines, I do get a result.

Any help please ?
By default, Drupal use "Full_ group_by" so that why you need to Group all your fields.

If you want disable it and group only on one field, you have to update setting.php 

Add this : 

$databases['default']['default'] ['init_commands'] = [
'sql_mode' =&gt; "SET sql_mode = 'STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER'",
];