运行 这个查询没有改变 sql_mode
Run this query without changing the sql_mode
我正在尝试在如下测试环境中测试查询
查询:-
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
将查询移动到选择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
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
我正在尝试在如下测试环境中测试查询
查询:-
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
将查询移动到选择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
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