我希望得到一个运行的每日,每周和每月的总数,我发出的消息。大约有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
1条答案
按热度按时间odopli941#
看起来我可以直接用+