如何枚舉執行查詢,我通過「seasson」,它顯示了我,作爲一個結果,與司機,點,構造和位置的排名相關的信息。PostgreSQL的存儲過程:我想查詢
我想要的是有這樣的事情:
POS IN RANKING | DRIVER NAME | CONSTRUCTOR NAME | POINTS
---------------------------------------------------------
1 "Hamilton" MC Laren 360
2 "Alonso" Ferrari 290
... ... ....
我得到的problema的是,我無法枚舉行。我認爲「POS排名」應該是row_number()函數的結果,但對於某些reasson我不能使它工作。
這是我的存儲功能:
CREATE TYPE ranking_t AS (
pos integer,
driver character varying(30),
constructor character varying(30),
points integer
);
CREATE OR REPLACE FUNCTION pra2.GetRankingOfPilots(sea pra2.season.name%type)
RETURNS ranking_t AS $$
DECLARE
ranking_pilots ranking_t;
BEGIN
SELECT
row_number() OVER (ORDER BY totalpuntos),
driver.name driver,
constructor.name constructor,
season.name season,
CAST(sum(runs.points) AS int) TotalPuntos
INTO ranking_pilots
FROM
pra2.hired hired
INNER JOIN pra2.constructor on hired.name_constructor = pra2.constructor.name
INNER JOIN pra2.driver on hired.num_driver = pra2.driver.num
INNER JOIN pra2.runs on pra2.driver.num=pra2.runs.num_driver
INNER JOIN pra2.race on pra2.runs.name_race=pra2.race.name AND pra2.runs.season_fk=pra2.race.season_fk AND pra2.runs.season_fk=pra2.race.season_fk
INNER JOIN pra2.season on hired.name_season=pra2.season.name AND pra2.race.season_fk=pra2.season.name
WHERE
pra2.season.name=sea
GROUP BY
season,driver,constructor
ORDER BY
TotalPuntos Desc;
END;
$$
LANGUAGE plpgsql;
我將不勝感激任何意見。
預先感謝您!
阿隆索不在法拉利或漢密爾頓與邁凱輪:P,只是說。 –
'我無法做到這一點。'問題是什麼?任何錯誤? –
是的,錯誤是,我嘗試枚舉查詢,並通過我使用的函數row_number()的方式,它會產生一個錯誤,因爲它說,字段totalpuntos不存在 – galeonweb