问题描述
如何在Druid sql中获取当前日期之前7天的日期?我在Postgres sql中做过类似的事情
CURRENT_DATE - interval '7 day'
我需要在Druid SQL查询中做同样的事情
解决方法
使用# Generate the colors
stations = unique(DSF_moments$station)
station_cols = scales::hue_pal()(length(stations))
# Assign them alphabetically (ggplot's default,which you don't seem to modify) names(station_cols) = sort(stations)
# use these colors for (some) of these stations in a plot with
scale_color_manual(values = station_cols)
或timestamp_expr { + | - } <interval_expr>
-请参阅https://druid.apache.org/docs/latest/querying/sql.html#time-functions上的文档,它们也解释了两者之间的区别。
您可以像这样使用timestampadd函数:TIMESTAMPADD(DAY,-7,CURRENT_TIMESTAMP)
,并且可以在select语句的where子句中使用它,以显示大于或等于7天的记录,如下所示: select * from "testdatasource" WHERE "__time" >= TIMESTAMPADD(DAY,CURRENT_TIMESTAMP)
如果要将其舍入到午夜,则可以使用date_trunc函数将其嵌套,如下所示: DATE_TRUNC('DAY',TIMESTAMPADD(DAY,CURRENT_TIMESTAMP))