如果 sysdate 大于 10th,则 Hive-Query 获取从当月 10 日到当前日期的数据,否则查询从上个月的 10 日到 sysdate

Hive-Query to get data from 10th of current month to current date if sysdate is greater than 10th else query from 10th of previous month to sysdate

我有一个要求,我需要查询从当前日期到本月前 10 号的数据集。 示例 - 如果日期是今天的 1 月 27 日,那么查询将考虑从 1 月 10 日到 1 月 27 日的数据。

如果当前日期小于本月 10 日,则查询应考虑从上个月 10 日到当前日期的数据。 示例 - 如果日期是今天的 1 月 3 日,那么查询应该考虑从 12 月 10 日到 1 月 3 日的数据。

我已尝试使用以下查询来获取第一种情况的结果。

select * from my_table
where partition_col >= date_add(current_date,1 - day(current_date)+9)
and partition_col <= current_date;

任何人都可以在单个查询中帮助管理第一个场景。

像这样使用 CASE 表达式:

where partition_col >= case when day(current_date)>=10 
                            then date(concat(substr(current_date,1,7), '-10'))
                            else date(concat(substr(add_months(current_date,-1),1,7),'-10'))
                       end
     and partition_col <= current_date;