有没有办法在Hive HQL中将两列相加到另一列?

Pop*_*orn 0 hadoop hive mapreduce hiveql

我希望每天,每周和每月运行我发送的邮件数量.大约有500种不同的消息类型.

我有以下表格:

Table name: messages

int message_type
BIGINT num_sent
string date

Table name: stats

int message_type
BIGINT num_sent_today
BIGINT num_sent_week
BIGINT num_sent_month
Run Code Online (Sandbox Code Playgroud)

表消息每天更新,包含今天日期的新行.我可以每天运行一个单独的配置单元查询来更新stats表吗?注意我无法通过直接查询消息表来获取运行计数,WHERE date >= 30 days ago因为表太大了.我必须添加/减去表统计中的每日值.像这样的东西:

// pseudocode
// Get this table (call it table b) from table messages

   int message_type
   BIGINT num_sent_today
   BIGINT num_sent_seven_days_ago
   BIGINT num_sent_thirty_days_ago

// join b with table stats so that I can

// Set stats.num_sent_today = b.num_sent_today
// Set stats.num_sent_week = stats.num_sent_week + b.num_sent_today - b.num_sent_seven_days_ago
// Set stats.num_sent_month = stats.num_sent_month + b.num_sent_today - b.num_sent_thirty_days_ago
Run Code Online (Sandbox Code Playgroud)

Pop*_*orn 5

看起来我可以直接用+添加列