0

私は完璧に機能しているこのselect句を持っています:

SELECT 
    "Aspectos"."ID" AS "Aspecto Normativo ID", 
    "Aspectos"."Aspecto" AS "Aspecto Normativo",        
    "Fatores"."ID", "Fatores"."Fator" AS "Fator Normativo",
    "Diagnostico"."Vinculo_Final", 
    "Fatores_1"."ID", 
    "Fatores_1"."Fator" AS "Fator Determinativo", 
    "Aspectos_1"."ID" AS "Aspecto Determinativo ID", 
    "Aspectos_1"."Aspecto" AS "Aspecto Determinativo", 
    Count("Itens"."ID") AS "No Itens", 
    Count("Itens"."ID") AS "Pri"
FROM "Diagnostico" INNER JOIN ("Aspectos" AS "Aspectos_1" 
INNER JOIN (("Fontes" INNER JOIN "Itens" ON "Fontes"."ID" = "Itens"."Fonte") 
INNER JOIN ("Fatores" AS "Fatores_1" 
INNER JOIN ("Aspectos" 
INNER JOIN ("Vinculos" 
INNER JOIN "Fatores" 
ON "Vinculos"."Fator_Normativo" = "Fatores"."ID") 
ON ("Aspectos"."ID" = "Fatores"."Aspecto") 
AND ("Aspectos"."ID" = "Fatores"."Aspecto")) 
ON "Fatores_1"."ID" = "Vinculos"."Fator_Determinativo") 
ON "Itens"."ID" = "Vinculos"."Item") 
ON "Aspectos_1"."ID" = "Fatores_1"."Aspecto") 
ON "Diagnostico"."ID" = "Vinculos"."Diagnostico_ID"
GROUP BY "Aspectos"."ID", "Aspectos"."Aspecto", 
          "Fatores"."ID", "Fatores"."Fator", 
          "Diagnostico"."Vinculo_Final", 
          "Fatores_1"."ID", 
          "Fatores_1"."Fator", 
          "Aspectos_1"."ID", 
          "Aspectos_1"."Aspecto"
ORDER BY  "Aspectos"."ID", "Aspectos_1"."ID", 
         "Fatores"."Fator", "Fatores_1"."Fator";

しかし、これと同じ選択でビューを作成しようとすると、次のエラーが発生します。

ERROR: column "ID" specified more than one time

誰でもこれについて私を助けることができます. ありがとう

4

1 に答える 1

2

"Fatores"."ID"(4 行目) と(6 行目)があります"Fatores_1"."ID"。それらに異なるエイリアスを与えます。

このような複雑なクエリの場合、見やすくするために、ステートメントの行ごとに 1 列のみにすることをお勧めします。また、常に列にエイリアスを与えることをお勧めします。

于 2013-02-20T16:40:44.393 に答える