【发布时间】:2020-10-20 22:22:11
【问题描述】:
user_db 架构是这样的:
2020-03 11 80 121
2020-04 20 30 121
2020-05 13 99 121
2020-06 12 19 121
......
老用户数据库是这样的:
month,user_count, total, grand_total, percentage_old, total_percentage_old
....
2020-06 20 30 121 73.3% 18.1%
需要在 Athena 查询中从 6 月更新值百分比、total_percentage 和旧数据数据库记录 percent_old、total_percentage_old,
with user_db as (
select *, user_count/total*100 as percentage, user_count/grand_total*100 as total_percentage
)
INSERT INTO user_db (percentage,total_percentage)
select percentage_old, total_percentage_old
from old_user_db as u
where u.month = '2020-06'
但出现此错误:
外部输入 'INSERT' 期望 {'(', ',', 'SELECT', 'VALUES', '表'}
需要保留 with 子句以便在其他查询中重复使用。 期望使用旧用户 db 值获得具有 6 月百分比和 total_percentage 的 user_db 表。
【问题讨论】:
-
样本数据和期望的结果真的很有帮助。
-
Athena 不支持向现有行添加字段。
INSERT INTO将始终添加新行。
标签: sql amazon-athena