大家好日子,我想在我的查询中提出这个问题。当按功能分组使用解密功能时会出现这个问题。
SELECT decrypt(a.email_address, 'secret', 'aes') AS email_address,
decrypt(atx.account_description, 'secret', 'aes') AS account_description,
a.account_id, a.account_type_id
FROM account_type AS atx
INNER JOIN accounts AS a ON atx.account_type_id=a.account_type_id
GROUP BY email_address
表格字段是:
Account_type <- table names
account_type_id - INT
account_description - BYTEA
Accounts <- table names
account_id - INT
account_type_id - INT
email_address - BYTEA
错误显示此文件
ERROR: column "atx.account_description" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: SELECT decrypt(atx.account_description, 'secret', 'aes') AS ...
我在GROUP BY上做错了吗?请注意。
但是当你在MYSQL上查询这样的东西时没有遇到任何问题。至于postgres是严格的方式。我很抱歉我还是postgres的新手。这是我第一次见到。我在新系统上使用postgres。
答案 0 :(得分:1)
像这样更改您的查询
SELECT decrypt(a.email_address, 'secret', 'aes') AS email_address,
decrypt(atx.account_description, 'secret', 'aes') AS account_description,
a.account_id, a.account_type_id
FROM account_type AS atx
INNER JOIN accounts AS a ON atx.account_type_id=a.account_type_id
GROUP BY email_address,atx.account_description,a.account_id,a.account_type_id
您必须在选择列表中指定哪些列不包含agg。功能列