2012-01-03 25 views
1

我想說出我認爲一個新列...這裏是(部分)我的代碼:PostgreSQL的視圖列命名

SELECT co_url_name, score_combined,(SELECT trunc(("productAndServices" + "futurePurchase" + shipping + "customerService" + returns + "lifetimeRating")/6, 2) AS resellerRating) 

基本上它只是一堆列的平均值。

但是,列出現名爲?column?而不是,我想知道如何改變我的語法來改名列resellerRating

我試過ALTER VIEW myview RENAME COLUMN "?column?" TO resellerRating;並沒有意外地得到一個錯誤....任何人都可以幫我解決這個問題嗎?

回答

1

視圖定義改成這樣:

SELECT 
    co_url_name, 
    score_combined, 
    (SELECT trunc(("productAndServices" + "futurePurchase" + shipping + "customerService" + returns + "lifetimeRating")/6, 2)) AS resellerRating 

如果你想在這裏發表您的整個查詢,我可以重構,但因爲它是,你需要把別名的子查詢之外。

+0

我很欣賞這個提議,但是這完美地回答了我的問題。我會盡快接受你的回答!謝謝! – tnw 2012-01-03 19:29:09