所以我有以下查询,它给了我标题中的错误。我不知道为什么它会给我错误。
CREATE OR REPLACE VIEW AUSTRALIANMEDALTALLY
AS
SELECT concat(SG_HOSTCITY, SG_YEAR) as 'ioc_game',
SUM(p.part_gold) as 'gold_medals',
SUM(p.part_silver) as 'silver_medals',
SUM(p.part_bronze) as 'bronze_medals'
FROM GAMES.SUMMERGAMES, GAMES.PARTICIPATION
WHERE COUNTRY_ISOCODE = AUS
GROUP BY COUNTRY_ISOCODE;
知道我为什么会收到错误吗?
答案 0 :(得分:4)
除了AUS
需要引用为'AUS'
之外,您的别名还需要双引号:
SELECT concat(SG_HOSTCITY, SG_YEAR) as "ioc_game",
使它们区分大小写或根本不引用:
SELECT concat(SG_HOSTCITY, SG_YEAR) as ioc_game,
其他别名也一样。
您还可以将p
称为表格别名,但是您没有定义 - 可能是participants
的 - 并且您没有定义表是相关的,因此您正在进行交叉连接。好像你可能在两个表中都有这个国家,所以你需要在引用前加上表别名。
您按照选择列表中没有列的列进行分组,这会导致自己的错误;你需要按照你没有聚合的任何列进行分组。
CREATE OR REPLACE VIEW AUSTRALIANMEDALTALLY
AS
SELECT concat(s.SG_HOSTCITY, s.SG_YEAR) as ioc_game,
SUM(p.part_gold) as gold_medals,
SUM(p.part_silver) as silver_medals,
SUM(p.part_bronze) as bronze_medals
FROM GAMES.SUMMERGAMES s
JOIN GAMES.PARTICIPATION p
ON p.gamesno = s.gamesno
WHERE p.COUNTRY_ISOCODE = 'AUS'
GROUP BY s.SG_HOSTCITY, s.SG_YEAR;
答案 1 :(得分:3)
WHERE COUNTRY_ISOCODE = AUS
更改为
WHERE COUNTRY_ISOCODE = 'AUS'