简单的“WHERE”查询出错

时间:2017-07-04 08:42:45

标签: postgresql

我在物化视图中创建新列时遇到问题。我正在尝试创建此列,以便在预期点击率列中的行=“平均值”时,它将返回该行中的展示次数的计算。据我所知,一切都是相应的。但是我收到以下错误消息。

ERROR:  syntax error at or near "clickthrough"
LINE 2: SELECT SUM("Impressions" * 1 ) WHERE Expected clickthrough r...
                                                  ^
********** Error **********

ERROR: syntax error at or near "clickthrough"
SQL state: 42601
Character: 94

在我看来,我在这里做出的任何不同变化都会出现在类似的错误消息中。

有没有人知道这个解决方案?整个查询是错误的吗?

CREATE MATERIALIZED VIEW adwords_calculated AS
SELECT SUM("Impressions" * 1 ) WHERE Expected clickthrough rate = "Average" 
AS Average Clickthrough Rate   
from adwords_initial;

当前列

Impressions| Expected clickthrough rate
-----------+----------------------------
1          |--
66         |--
12         |Average
13         |--
1000       |Above Average
45         |Average
4          |Below Average

欲望结果

Impressions| Expected clickthrough rate |Average Clickthrough Rate
-----------+----------------------------+-----------------
1          |--                          |0
66         |--                          |0
12         |Average                     |12
13         |--                          |0
1000       |Above Average               |0
45         |Average                     |45
4          |Below Average               |0

最终结果,(评论中每个请求添加了其他列。

Impressions| Expected clickthrough rate |Average CTR| Country
-----------+----------------------------+-----------+----------
1          |--                          |0          |USA 
66         |--                          |0          |Germany
12         |Average                     |12         |Austria
13         |--                          |0          |UK
1000       |Above Average               |0          |China
45         |Average                     |45         |USA
4          |Below Average               |0          |Germany

1 个答案:

答案 0 :(得分:1)

如果确实需要这样的列名,则必须使用双引号将其转义。字符串文字必须用单引号括起来。此外,条款的顺序是错误的。它应该是

SELECT expression AS alias
FROM table
WHERE condition;