在hivehql中有没有一种方法可以将两列相加成另一列?

ruyhziif  于 2021-05-30  发布在  Hadoop
关注(0)|答案(1)|浏览(473)

我希望得到一个运行的每日,每周和每月的总数,我发出的消息。大约有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

表消息每天都会更新为今天的日期的新行。我是否可以每天运行一个配置单元查询来更新 stats table?注意,我无法通过直接使用查询messages表来获取运行计数 WHERE date >= 30 days ago 因为table太大了。我必须从表的统计数据中加/减每日值。像这样:

// 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

相关问题