2016-09-02 41 views
-1
SELECT * 
FROM 
(SELECT 
"public".steponesection.datesection, 
"public".steponesection."Trade Price", 
max ("public".steponesection."Trade Volume") OVER (partition by "public".steponesection.datesection) as max_Volm 

FROM "public".steponesection)t 

WHERE "public".steponesection."Trade Volume" = max_Volm 

結果:我希望每個datesection的最大音量,但是當我運行它顯示了此錯誤

[Err] ERROR: missing FROM-clause entry for table "steponesection" 
LINE 10: WHERE "public".steponesection."Trade Volume" = max_Volm 

    ^

回答

0

的錯誤信息是非常明確的:where子句不能引用steponesection上的該級別查詢沒有該名稱的標識符。派生表被稱爲t,這就是你需要使用的。

您還沒有選擇在內部查詢的"Trade Volume",所以它在外部水平是不可用:

SELECT * 
FROM (
    SELECT "public".steponesection.datesection, 
      "public".steponesection."Trade Price", 
      "public".steponesection."Trade Volume", --<< missing 
      max ("public".steponesection."Trade Volume") OVER (partition by "public".steponesection.datesection) as max_volm 
    FROM "public".steponesection 
) t 
WHERE t."Trade Volume" = t.max_volm --<< use the alias of the derived table 

我會強烈建議避免像"Trade Price"帶引號的標識符。他們從長遠來看更麻煩,那麼他們是值得的

相關問題