无法在配置单元 table 中使用 CTE 来编写查询
Unable to use CTE in hive table to write a query
WITH month_revenue AS
(SELECT SUM(price) AS Oct_Revenue FROM attribute_partition WHERE event_type= 'purchase' AND
MONTH(event_time) = '10') ,
(SELECT SUM(price) AS Nov_Revenue FROM attribute_partition WHERE event_type= 'purchase' AND
MONTH(event_time) = '11')
SELECT (Oct_Revenue - Nov_Revenue) FROM month_revenue ;
编写查询以查找从 10 月到 11 月由于购买而产生的收入变化。
我得到的错误是:
FAILED: ParseException line 2:0 missing ( at 'SELECT' near ',' in
statement line 2:117 missing ) at ',' near ',' in statement line 3:0
cannot recognize input near 'SELECT' 'SUM' '(' in statement
请帮助我了解我哪里做错了
一个 CTE 是一个查询。可以像这样在单个语句中计算两个月:
WITH month_revenue AS
(SELECT
SUM(case when MONTH(event_time) = '10' then price else 0 end) AS Oct_Revenue,
SUM(case when MONTH(event_time) = '11' then price else 0 end) AS Nov_Revenue
FROM attribute_partition
WHERE event_type= 'purchase'
AND MONTH(event_time) in ('10', '11')
)
SELECT (Oct_Revenue - Nov_Revenue) FROM month_revenue ;
WITH month_revenue AS
(SELECT SUM(price) AS Oct_Revenue FROM attribute_partition WHERE event_type= 'purchase' AND
MONTH(event_time) = '10') ,
(SELECT SUM(price) AS Nov_Revenue FROM attribute_partition WHERE event_type= 'purchase' AND
MONTH(event_time) = '11')
SELECT (Oct_Revenue - Nov_Revenue) FROM month_revenue ;
编写查询以查找从 10 月到 11 月由于购买而产生的收入变化。 我得到的错误是:
FAILED: ParseException line 2:0 missing ( at 'SELECT' near ',' in statement line 2:117 missing ) at ',' near ',' in statement line 3:0 cannot recognize input near 'SELECT' 'SUM' '(' in statement
请帮助我了解我哪里做错了
一个 CTE 是一个查询。可以像这样在单个语句中计算两个月:
WITH month_revenue AS
(SELECT
SUM(case when MONTH(event_time) = '10' then price else 0 end) AS Oct_Revenue,
SUM(case when MONTH(event_time) = '11' then price else 0 end) AS Nov_Revenue
FROM attribute_partition
WHERE event_type= 'purchase'
AND MONTH(event_time) in ('10', '11')
)
SELECT (Oct_Revenue - Nov_Revenue) FROM month_revenue ;