您可以使用“数字”功能生成零值。然后使用UNIOn ALL将查询和零值连接起来,并且已经根据获取的数据进行了GROUP BY。
因此,您的查询将如下所示:
SELECt SUM(metric), time FROM ( SELECt toStartOfQuarter(toDate(1514761200+number*30*24*3600)) time, toUInt16(0) AS metric FROM numbers(30) UNIOn ALL SELECt toStartOfQuarter(created_at) AS time, metric FROM mytable WHERe created_at >= toDate(1514761200)AND created_at >= toDateTime(1514761200)AND created_at <= toDate(1546210800)AND created_at <= toDateTime(1546210800) ) GROUP BY time ORDER BY time
注意toUInt16(0)-零值必须与以下类型相同
metrics
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)