我试图创建一个包含来自其他表的计算数据的视图。但是,我收到以下错误消息:[42701] ERROR: column "id" specified more than once
.
我的SQL脚本:
CREATE VIEW dashboard_view AS
SELECT c.libelle_commune AS "commune",
count(bv.id) AS "total_bv",
count(rsb.id) AS "bv_saisis",
count(bv.id) - count(rsb.id) AS "bv_en_attente",
count(rsb.id) / count(bv.id) * 100 AS "pourcentage_saisie",
count(rsb_t.id) AS "bv_transmis_sie2",
count(rsb_t.id) / count(bv.id) * 100 AS "pourcentage_transmission",
d.id,
c.id
FROM commune "c"
JOIN departement "d" ON d.id = c.departement_id
JOIN bureau_de_vote "bv" ON bv.commune_id = c.id
LEFT JOIN scrutin_bureau "sb" ON sb.bureau_de_vote_id = bv.id
LEFT JOIN resultat_scrutin_bureau "rsb" ON rsb.scrutin_bureau_id = sb.id
LEFT JOIN resultat_scrutin_bureau "rsb_t" ON (
rsb_t.scrutin_bureau_id = sb.id
AND rsb_t.etat_id = (SELECT id FROM etat WHERE code = 'transmission')
)
JOIN election ON sb.election_id = election.id
GROUP BY c.id, d.id;
2条答案
按热度按时间qvk1mo1f1#
您正在选择
这两列不能同时出现在名为
id
的视图中-您需要至少为其中一列提供别名,可能两列都使用描述id
所代表内容的别名。8yoxcaq72#
由于错误指定,您尝试在查询中创建两个名为
id
列一个非常简单的错误视图创建示例,具有相同的错误:
纠正一个
因此,为了修复查询更改
进入