我有以下查詢可以在我的測試框上正常運行,但不適用於我的生產框。問題是什麼?mysql查詢在不同的服務器上給出不同的結果
SELECT
*,
round(priceperkm * IFNULL(KMPlanned, projects.KM),
4) AS NEWVALUE,
round(PRICE * IFNULL(KMPlanned, projects.KM),
2) AS TotalPriceForItem,
SUM(((abs(FSP - LSP) + 1) * SI)/1000) AS KM_Completed,
round(SUM(((abs(FSP - LSP) + 1) * SI)/1000) * PRICE,
2) AS TotalPrice,
round((SUM(((abs(FSP - LSP) + 1) * SI)/1000) * PRICE)/(PRICE * IFNULL(KMPlanned, projects.KM)) * 100,
2) AS TotalPercent
FROM
hdb.projects
join
biditems ON projects.id = biditems.project_id
join
lookupprocess ON biditems.ITEMID = lookupprocess.biditems_id
left join
jobsprocesscomplete ON lookupprocess.ID = lookupprocess_id
left join
detailsseismic ON jobsprocesscomplete.JOBNO = detailsseismic.JOBNO
where
projects.PROJID = 1402013
and lookupprocess.ID = 13138
錯誤:
2014/02/24 18:37:06 [error] [system.db.CDbCommand] CDbCommand::() failed: SQLSTATE[42000]: Syntax error or access violation: 1140 Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause. The SQL statement executed was:
.
2014/02/24 18:37:06 [error] [exception.CDbException] exception 'CDbException' with message 'CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1140 Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause' in /data/intranet/html/yii-1.1.14/framework/db/CDbCommand.php:543
Stack trace:
#0 /data/intranet/html/yii-1.1.14/framework/db/CDbCommand.php(377): CDbCommand->queryInternal('', 0, Array)
#1 /data/intranet/html/paradox/protected/controllers/GlobalController.php(260): CDbCommand->query()
#2 /data/intranet/html/paradox/protected/controllers/ProjectsController.php(648): GlobalController->lookupprocesstotal('1402013', Array)
#3 [internal function]: ProjectsController->actionUpdate('12768')
#4 /data/intranet/html/yii-1.1.14/framework/web/actions/CAction.php(108): ReflectionMethod->invokeArgs(Object(ProjectsController), Array)
#5 /data/intranet/html/yii-1.1.14/framework/web/actions/CInlineAction.php(47): CAction->runWithParamsInternal(Object(ProjectsController), Object(ReflectionMethod), Array)
#6 /data/intranet/html/yii-1.1.14/framework/web/CController.php(308): CInlineAction->runWithParams(Array)
#7 /data/intranet/html/yii-1.1.14/framework/web/CController.php(286): CController->runAction(Object(CInlineAction))
#8 /data/intranet/html/yii-1.1.14/framework/web/CController.php(265): CController->runActionWithFilters(Object(CInlineAction), Array)
#9 /data/intranet/html/yii-1.1.14/framework/web/CWebApplication.php(282): CController->run('update')
#10 /data/intranet/html/yii-1.1.14/framework/web/CWebApplication.php(141): CWebApplication->runController('projects/update')
#11 /data/intranet/html/yii-1.1.14/framework/base/CApplication.php(180): CWebApplication->processRequest()
#12 /data/intranet/html/paradox/index.php(31): CApplication->run()
#13 {main}
REQUEST_URI=/sidb/index.php?r=projects/update&id=12768
HTTP_REFERER=http://intranet/sidb/index.php?r=projects/admin
UPDATE 兩個服務器都在下面提供 SELECT @@ GLOBAL.sql_mode相同的結果; + ------------------- + | @@ GLOBAL.sql_mode | + ------------------- + | | + ------------------- + 1行中集(0.00秒)
mysql> SELECT @@SESSION.sql_mode;
+--------------------+
| @@SESSION.sql_mode |
+--------------------+
| |
+--------------------+
1 row in set (0.00 sec)
mysql> show variables like 'sql_mode'
-> ;
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| sql_mode | |
+---------------+-------+
,如果我在查詢的末尾添加group by lookupprocess.ID
會發生什麼。它會返回相同的結果嗎?
您的poduction服務器可能已打開ONLY_FULL_GROUP_BY選項,而測試服務器尚未打開,請參閱此鏈接瞭解詳細信息:http://dev.mysql.com/doc/refman/5.1/en/server-sql- mode.html#sqlmode_only_full_group_by – krokodilko