我的表是这样的:总和列的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查询 –