我有一個Postgres SQL數據庫,有測驗,問題,答案和標記在那裏(多個表)我試圖編寫一個查詢來計算一個測驗的最高分,然後使用剛剛計算出的查詢來更新測驗表最高分有沒有什麼辦法來存儲查詢中的值,然後在下面的查詢中使用它?
我的繼承人querys
SELECT SUM(maxscore)
FROM (
SELECT max(answer.answermark) AS maxscore
FROM answer, questions
WHERE questions.quizid = 1 AND answer.questionid = questions.questionid
GROUP BY answer.questionid
) scr;
UPDATE quiz
SET maxscore = '50'
WHERE quizid = 1
其中「SET maxscore = '50'
」我需要的不是鍵入50,我需要使用計算從上面的查詢,有什麼辦法?
感謝
http://stackoverflow.com/questions/12328198/store-the-query-result-in -variable-using-postgresql-stored-procedure –