我正在尝试在测试环境中测试查询,如下所示
查询: -
SELECT a.aggreatorid AS aggreatorid, '' AS txndesc, DATE_FORMAT(DATE(b.txndate),'%d/%m/%Y') AS txndate,
SUM(txncredit) AS txncredit, SUM(txndebit) AS txndebit
FROM walletmast a INNER JOIN wallettransaction b ON a.walletid=b.walletid
AND txndate BETWEEN CURDATE() - INTERVAL 3 DAY AND CURDATE()
GROUP BY a.aggreatorid, DATE(b.txndate)
ORDER BY txndate DESC
查询正在抛出
错误: -
SQL Error (1055): 'digitalpurse.b.txnDate' isn't in GROUP BY
查询在我的本地环境中工作,但在大量搜索后没有在测试环境中查找我发现测试环境有 sql_modes ,无法根据应用程序流程和安全目的进行更改
SQL模式: -
@@sql_mode |
+------------------------------------------------------------+
| ONLY_FULL_GROUP_BY,
STRICT_TRANS_TABLES,
NO_ZERO_IN_DATE,
NO_ZERO_DATE,
ERROR_FOR_DIVISION_BY_ZERO,
NO_AUTO_CREATE_USER,
NO_ENGINE_SUBSTITUTION |
有没有办法在不更改sql_mode的情况下运行此查询? 如果需要任何其他信息,请与我们联系。提前谢谢你:D
答案 0 :(得分:1)
将查询移动到选择DATE(b.txndate)
的子查询中,使其与GROUP BY
子句匹配,然后在主查询中执行格式化。
SELECT aggreatorid, '' AS txndesc, DATE_FORMAT(txndate, '%d/%m/%Y') AS txndate,
txncredit, txndebt
FROM (
SELECT a.aggreatorid AS aggreatorid, DATE(b.txndate) AS txndate,
SUM(txncredit) AS txncredit, SUM(txndebit) AS txndebit
FROM walletmast a
INNER JOIN wallettransaction b ON a.walletid=b.walletid
WHERE txndate BETWEEN CURDATE() - INTERVAL 3 DAY AND CURDATE()
GROUP BY a.aggreatorid, DATE(b.txndate)
) AS x
ORDER BY txndate DESC
答案 1 :(得分:1)
SELECT a.aggreatorid
, '' txndesc
, DATE_FORMAT(DATE(b.txndate),'%d/%m/%Y') dt
, SUM(txncredit) txncredit
, SUM(txndebit) txndebit
FROM walletmast a
JOIN wallettransaction b
ON a.walletid=b.walletid
AND txndate BETWEEN CURDATE() - INTERVAL 3 DAY AND CURDATE()
GROUP BY a.aggreatorid, dt, txndesc
ORDER BY txndate DESC
就个人而言,我认为最好的日期出现在最终用户区域设置中,所以练习JavaScript或PHP而不是MySQL