在不更改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的练习

相关内容

  • 没有找到相关文章

最新更新