2017-01-23 59 views
0

我試圖測試在測試環境是如下運行此查詢不改變的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

+0

的[可能的複製沒有任何\ _Value能力爲MySQL 5.6?](http://stackoverflow.com/questions/37089347/is-there-any-value-capability-for-mysql-5-6) – e4c5

+0

@Strawberry做到了這一點,但查詢返回的數據並不正確發佈此問題的需求 – abhi314

+0

您使用的是哪個版本的MySQL?如果它是5.7,你可以使用'ANY_VALUE()'。 – Barmar

回答

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
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的