我的表是這樣的:總和列的PostgreSQL
CREATE TABLE public."Payments"
(
user_id integer,
"1 month later" numeric(19,4),
"2 months later" numeric(19,4),
"3 months later" numeric(19,4),
"4 months later" numeric(19,4),
"5 months later" numeric(19,4),
"6 months later" numeric(19,4),
"7 months later" numeric(19,4),
"8 months later" numeric(19,4),
"9 months later" numeric(19,4),
"10 months later" numeric(19,4),
"11 months later" numeric(19,4),
"12 months later" numeric(19,4)
與內部數據exampe這樣的:
INSERT INTO "Payments" ("user_id", "1 month later", "2 months later", "3 months later", "4 months later", "5 months later", "6 months later", "7 months later", "8 months later", "9 months later", "10 months later", "11 months later", "12 months later") VALUES (134329, 190, 190, 190, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
我需要得到SUMM爲每個用戶ID,有很多其中。 postgres中有哪些函數可以快速執行?
首先,你爲什麼要把'x個月後'分成不同的列。這違反了正常形式的規則。你想要做的是一個簡單的總和。你應該谷歌而不是在這裏發佈一個問題。 – 2016-04-15 00:44:27
我同意埃裏克。你應該停下來閱讀關於關係數據的好書。你走錯了路。 –
它只是一個例子,我已經在訪問這個表,我需要將它轉換爲psql和wright psql查詢 –