我已经阅读了一些与我的错误有关的帖子,但是没有一个解决方案似乎有效。我对SQL很新,所以很抱歉,如果它真的很简单。我有两张桌子
电影广告资源 - 其中包含movie_title,onhand_qty和replacement_price
NotFlix - 有subscriber_name,queue_nbr和movie_title
我正在尝试加入这两个表来输出每个客户的总重置价格成本,但是当我这样做时会给出上面标题的错误。这是我的代码,提前感谢任何帮助!
SELECT subscriber_name, SUM (replacement_price) as replacement
FROM
(SELECT NotFlix.subscriber_name, NotFlix.movie_title, NotFlix.queue_nbr, MovieInventory.replacement_price
FROM NotFlix
INNER JOIN MovieInventory
ON NotFlix.movie_title = MovieInventory.movie_title
)
GROUP BY subscriber_name;
答案 0 :(得分:1)
您缺少别名:
SELECT AliasNameHere.subscriber_name, SUM (AliasNameHere.replacement_price) as replacement
FROM
(SELECT NotFlix.subscriber_name as subscriber_name, NotFlix.movie_title, NotFlix.queue_nbr, MovieInventory.replacement_price as replacement_price
FROM NotFlix
INNER JOIN MovieInventory
ON NotFlix.movie_title = MovieInventory.movie_title
) AliasNameHere
GROUP BY subscriber_name;
答案 1 :(得分:-1)
我只是不知道为什么你在FROM子句中做一个临时表,你可以在这里做一个基本的INNER JOIN,并且可以避免别名的问题:
SELECT NotFlix.subscriber_name, SUM (MovieInventory.replacement_price) as replacement
FROM NotFlix
INNER JOIN MovieInventory
ON NotFlix.movie_title = MovieInventory.movie_title
GROUP BY subscriber_name;