mysql查询错误SELECT列表不在GROUP BY子句中并包含非聚合列

时间:2016-11-28 10:08:43

标签: mysql

我正在使用pentaho报告,我的报告中有一个查询,我的查询在我的本地计算机上工作,但当我尝试将我的应用程序部署到服务器时,我收到此错误..

我正在使用mysql 5.6

    28-Nov-2016 09:47:38.490 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive /root/apache-tomcat-8.5.5/webapps/ROOT.war has finished in 44,957 ms
28-Nov-2016 09:47:38.496 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler [http-nio-80]
28-Nov-2016 09:47:38.502 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler [ajp-nio-8009]
28-Nov-2016 09:47:38.504 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 45038 ms
ERROR org.pentaho.reporting.engine.classic.core.layout.output.AbstractReportProcessor - 48154607: Report processing failed.
org.pentaho.reporting.engine.classic.core.ReportDataFactoryException: Failed at query: Select id, IFNULL(SUM(debet) - SUM(kredit),0) as saldoawal2 from (

SELECT
    g.id,
     g.code,
    a.trx_date,
    IF(a.trx_type = 1 OR a.trx_type = 2, a.relation,IF(a.trx_type = 3,e.name,IF(a.trx_type = 4,f.name, b.amount))) as relasi,
     a.trx_no,
     b.dt,
    IF(b.dt = 'D', b.amount,  0) as 'debet',
    IF(b.dt = 'K', b.amount,  0) as 'kredit'
FROM transaksi_kas_detail b     
     INNER JOIN transaksi_kas a  ON a.id = b.transaksi_kas_id
     LEFT OUTER JOIN customer e ON a.customer_id = e.id
     LEFT OUTER JOIN supplier f ON a.supplier_id = f.id
     LEFT OUTER JOIN invoice c ON b.sales_invoice_id = c.id
     LEFT OUTER JOIN purchase_invoice d ON b.purchase_invoice_id = d.id  
     LEFT OUTER JOIN account g ON b.account_id = g.id
WHERE g.id != '' 

UNION 

select 
    d.id,
    d.code,
    a.invoice_date as trx_date,
    b.name as relasi,
    a.invoice_no as trx_no,
    'D' as dt,
    a.total_amount as debet,
    0 as kredit
FROM
    invoice a
    LEFT JOIN customer b ON  a.customer_id = b.id
    LEFT JOIN group_customer c ON c .id = b.group_customer_id   
    LEFT JOIN account d ON d.id = c.piutang_dagang_id

union

select 
    d.id,
    d.code,
    a.purchase_date as trx_date,
    b.name as relasi,
    a.purchase_no as trx_no,
    'D' as dt,
    0 as debet,
    a.total_amount as kredit
FROM
    purchase_invoice a
    LEFT JOIN supplier b ON  a.supplier_id = b.id
    LEFT JOIN group_supplier c ON c .id = b.group_supplier_id   
    LEFT JOIN account d ON d.id = c.hutang_dagang_id

union

select 
    d.id,
    d.code,
    a.invoice_date as trx_date,
    b.name as relasi,
    a.invoice_no as trx_no,
    'D' as dt,
    a.total_amount as debet,
    0 as kredit
from
    invoice a
    LEFT JOIN customer b ON a.customer_id = b.id
    LEFT JOIN group_customer c ON b.group_customer_id = c.id
    LEFT JOIN account d ON c.uang_muka_id = d.id
    GROUP BY a.invoice_no
union

select 
    d.id,
    d.code,
    a.purchase_date as trx_date,
    b.name as relasi,
    a.purchase_no as trx_no,
    'D' as dt,
    0 as debet,
    a.total_amount as kredit
from
    purchase_invoice a
    LEFT JOIN supplier b ON a.supplier_id = b.id
    LEFT JOIN group_supplier c ON b.group_supplier_id = c.id
    LEFT JOIN account d ON c.uang_muka_id = d.id
    GROUP BY a.purchase_no
) ffasdff 
WHERE id =${acid} AND trx_date < ${dateFrom}
    at org.pentaho.reporting.engine.classic.core.modules.misc.datafactory.sql.SimpleSQLReportDataFactory.queryData(SimpleSQLReportDataFactory.java:210) ~[pentaho-reporting-engine-classic-core-5.1.0.0-752.jar:5.1.0.0-752.-1]
    at org.pentaho.reporting.engine.classic.core.modules.misc.datafactory.sql.SQLReportDataFactory.queryData(SQLReportDataFactory.java:162) ~[pentaho-reporting-engine-classic-core-5.1.0.0-752.jar:5.1.0.0-752.-1]

和这一个。

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'accounter.d.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

请参阅此行SELECT list is not in GROUP BY clause and contains nonaggregated column 'accounter.d.id'

我仍然不知道这是什么意思。

我必须做什么,我正在使用Fedora 24 x64。

1 个答案:

答案 0 :(得分:-1)

您正在使用子查询创建虚拟表,您将使用trx_no替换purchase_no,因为在group by子句中找不到它。 你必须在group by子句中使用trx_no。