【发布时间】:2017-04-17 22:02:22
【问题描述】:
这是我的 sql
$sqltable3=
'SELECT
"Publications"."Pub_ID",
"Questions"."Question"
FROM "Publications"
LEFT JOIN "Aspect_Pub_join" ON "Publications"."Pub_ID"="Aspect_Pub_join"."Pub_ID"
LEFT JOIN "Aspect_question_join" ON "Aspect_Pub_join"."Aspect_ID"="Aspect_question_join"."Aspect_ID"
LEFT JOIN "Questions" ON "Aspect_question_join"."Question_ID"="Questions"."Question_ID"
Where "Publications"."Pub_ID"=$1
GROUP BY "Questions"."Question"
ORDER BY "Publications"."Pub_ID" ASC';
这是错误:
警告:pg_query_params():查询失败:错误:列“Publications.Pub_ID”必须出现在 GROUP BY 子句中或用于聚合函数第 1 行:选择“Publications”。“Pub_ID”,“问题”。 “问题” FROM ... ^ in ...
我在 order by 中使用 Publications.Pub_ID 作为聚合函数,所以我不确定我哪里出错了?相同的查询在 mysql 中运行良好(我知道它不那么挑剔)。
如果我去掉 group by 和 order by 函数,那么 sql 会运行,但显然不会返回所需的结果。
【问题讨论】:
标签: php sql postgresql