PostgreSQL错误:列“收入”指定了多次

时间:2019-08-18 12:40:35

标签: postgresql

我正在尝试建立一个基本数据库,以帮助筛选许多CSV银行交易。

我已从多个帐户的多个表中导入所有交易,这些帐户的“扣除额”列已打勾为“ False”或“ True”

我正在尝试创建一个“创建视图”,以便将多个表中的数据推导出到一个表中以进行“扣除”。

基本; 来自多个具有收入列的表的银行交易显示为“ TRUE”

  

错误为-查询1错误:ERROR:指定了“收入”列的更多信息   不止一次

大约一天以来,我一直在尝试各种代码,但似乎无法使其正常工作。

keccak256 = require('js-sha3').keccak256;
var bytes = keccak256.digest();
console.log(bytes);

2 个答案:

答案 0 :(得分:2)

您的对帐单中有一个以上的收入列:app.setState({user: newUser})"EverydaySTG"."Income"。替换..:

"CC WTPC"."Income"

...作者:

CREATE VIEW "Deductions"
AS SELECT
    "EverydaySTG"."Income",
    "EverydaySTG"."Deduction",
    "EverydaySTG"."Date",
    "EverydaySTG"."Amount", 
    "EverydaySTG"."Payee",
    "CC WTPC"."Income",
    "CC WTPC"."Deduction",
    "CC WTPC"."Date",
    "CC WTPC"."Amount"
FROM
    "EverydaySTG", "CC WTPC"
WHERE (
    "EverydaySTG"."Deduction" = 'TRUE' ::text)
    Or ( "CC WTPC"."Deduction" = 'TRUE' ::text );

OP注释“结果是交易是水平填充的。不是收入,扣除额,日期,金额等整洁的单行。有没有办法使原始行保持完整,所以交易垂直堆叠?”

我了解他们希望改为使用UNION查询:

CREATE VIEW "Deductions"
AS SELECT
    "EverydaySTG"."Income" AS income_a,
    "EverydaySTG"."Deduction" AS deduction_a,
    "EverydaySTG"."Date" AS date_a,
    "EverydaySTG"."Amount" AS amount_a,
    "EverydaySTG"."Payee",
    "CC WTPC"."Income" AS income_b,
    "CC WTPC"."Deduction" AS deduction_b,
    "CC WTPC"."Date" AS date_b,
    "CC WTPC"."Amount" AS amount_b
FROM "EverydaySTG", "CC WTPC"
WHERE (
    "EverydaySTG"."Deduction" = 'TRUE' ::text)
    Or( "CC WTPC"."Deduction" = 'TRUE' ::text );

CREATE TABLE "EverydaySTG" (
    "Income" INTEGER
    "Deduction" CHARACTER VARYING
    "Date" DATE
    "Amount" INTEGER
    "Payee" CHARACTER VARYING
);

CREATE TABLE "CC WTPC" (
    "Income" INTEGER
    "Deduction" CHARACTER VARYING
    "Date" DATE
    "Amount" INTEGER
);

CREATE VIEW "Deductions_horizontal"
AS SELECT
    "EverydaySTG"."Income" AS income_a,
    "EverydaySTG"."Deduction" AS deduction_a,
    "EverydaySTG"."Date" AS date_a,
    "EverydaySTG"."Amount" AS amount_a,
    "EverydaySTG"."Payee",
    "CC WTPC"."Income" AS income_b,
    "CC WTPC"."Deduction" AS deduction_b,
    "CC WTPC"."Date" AS date_b,
    "CC WTPC"."Amount" AS amount_b
FROM "EverydaySTG", "CC WTPC"
WHERE (
    "EverydaySTG"."Deduction" = 'TRUE' ::text)
    Or( "CC WTPC"."Deduction" = 'TRUE' ::text );

答案 1 :(得分:0)

您的事实是您的部门从相同的列表中获得了相同的列名称,结果是相同的列名称,但是在sql中不能使用相同的列名称,因此必须更改,例如:

CREATE VIEW "Deductions" AS
SELECT
  "EverydaySTG"."Income",
  "EverydaySTG"."Deduction",
  "EverydaySTG"."Date",
  "EverydaySTG"."Amount",
  "EverydaySTG"."Payee",
  "CC WTPC"."Income" AS Income_cc_wtpc,
  "CC WTPC"."Deduction" AS Deduction_cc_wtpc,
  "CC WTPC"."Date" AS Date_cc_wtpc,
  "CC WTPC"."Amount" AS Amount_cc_wtpc
FROM
  "EverydaySTG",
  "CC WTPC"
WHERE (
  "EverydaySTG"."Deduction" = 'TRUE' ::text)
  Or(
    "CC WTPC"."Deduction" = 'TRUE' ::text
);