2016-03-26 21 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 - Kolon bu sorgu ile sorun nedir

yok?

+0

err, bok,. –

cevap

1

Sorun büyük olasılıkla, birleştirmenin değerlendirildiği anda sütun takma adının ayrıştırılmamış olması; yerine gerçek sütun adı kullanın: limit kullanırken

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; 

Ayrıca, gerçekten bir order by maddesi kullanmalıdır. Dokümanlar

:

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

sorun katılır çıktı sütun adları kullanılamaz olmasıdır. the documentation itibaren

: kapatmak için yanlışlıkla seçimler konusunda üzgün

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.