我有以下查询在我的测试盒上运行正常但在我的生产盒上不起作用。有什么问题?
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
更新 两台服务器都给出了相同的结果 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
会发生什么。它会返回相同的结果吗?
答案 0 :(得分:1)
您的select
子句同时具有列和聚合函数(sum()
)。这会将查询转换为只返回一行的聚合查询,这可能是也可能不是您想要的。 (我怀疑你确实想要group by
某些东西。)
无论如何,这都使用MySQL扩展。扩展由系统变量ONLY_FULL_GROUP_BY
控制。启用此选项后,将应用ANSI规则。阅读它here!。
您看到的行为表明在生产服务器上启用了ONLY_FULL_GROUP_BY
,但在开发服务器上没有启用{{1}}。您应该启用它或在两者中禁用它。
答案 1 :(得分:0)
我将两台服务器更新为存储库中可用的最新mysql版本。受影响的服务器有旧版本,我相信它不支持sql语句。