2014-09-17 11 views
-2

여러분 모두에게 좋은 날입니다. 제 질문에이 질문을 제기 할 것입니다.이 문제는 그룹별로 기능을 해독 할 때 발생합니다.포스트 그레스 그룹 발행물

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에서 이와 같은 질문을 할 때 문제는 발생하지 않습니다. 포스트 그레스는 엄격한 방법입니다. 미안하지만 나는 여전히 포스트그레스에 대해서 초보자입니다. 우리가 처음으로 포스트그레스를 사용하고 있습니다. 새로운 시스템.

+2

다시 오류를 다시 읽으십시오. 잘못된 것을 정확히 알려줍니다. 'account_description'은 그룹에 있거나'min' /'max'/etc에 있어야합니다. – Wolph

+1

'GROUP BY'는 무엇을 기대합니까? – bereal

+1

왜 그곳에'group by '을 가지고 있습니까? 집계를 사용하지 마십시오. 어떤 문제를 해결하려고합니까? –

답변

1
당신은 밖으로 AGG와 선택 목록에 열을 제공해야이

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 

같은 쿼리를 변경

. 함수 열

+1

그 postgre 행동은 어떻게합니까? MYSql에서 한 그룹으로 만 수행 할 수 있습니다 –

+0

정말 그룹의 모든 필드를 호출해야합니까? –

+1

읽기 http://stackoverflow.com/questions/1769361/postgresql-group-by-different-from-mysql @boyee – Sathish