2016-03-26 1 views
0
SELECT nmemail as order_email, 
     dtorder, 
     vlOrder, 
     cohorts.cohortdate 
FROM factorderline 
     JOIN (SELECT nmemail as cohort_email, Min(dtorder) AS cohortDate FROM factorderline GROUP BY cohort_email limit 5) cohorts 
ON order_email= cohort_email limit 5; 

ERROR: column "order_email" does not existPostgresのSQL - 列がこのクエリでの問題は何である

存在しないのですか?

+0

errは、がらくた、。 –

答えて

1

ほとんどの場合、列エイリアスの定義は、結合が評価された時点で解析されていない可能性があります。代わりに、実際の列名を使用します。limitを使用した場合

SELECT nmemail as order_email, 
     dtorder, 
     vlOrder, 
     cohorts.cohortdate 
FROM factorderline 
JOIN (
    SELECT nmemail as cohort_email, Min(dtorder) AS cohortDate 
    FROM factorderline 
    GROUP BY cohort_email limit 5 
) cohorts ON nmemail = cohort_email 
limit 5; 

また、あなたは本当にorder by句を使用する必要があります。ドキュメントから

When using LIMIT, it is important to use an ORDER BY clause that constrains the result rows into a unique order. Otherwise you will get an unpredictable subset of the query's rows.

1

問題は、出力列名が参加する中で使用することはできないということです。 the documentationから

:クローズする不慮の投票について申し訳ありません

An output column's name can be used to refer to the column's value in ORDER BY and GROUP BY clauses, but not in the WHERE or HAVING clauses; there you must write out the expression instead.

関連する問題