hive日期函数-广发实战(三)

近一月客户新增常规里程数与额度比即上个月 第一天(包含)到上个月最后一天(包含)

字段是batch_date==>格式是 yyyymmdd

select replace(trunc(add_months(current_date,-1),'MM'),'-','');
+-----------+--+
|    _c0    |
+-----------+--+
| 20181201  |
+-----------+--+
 select replace(trunc(current_date,'MM'),'-','');
+-----------+--+
|    _c0    |
+-----------+--+
| 20190101  |
+-----------+--+
--限定条件
where batch_date >= replace(trunc(add_months(current_date,-1),'MM'),'-','') and batch_date< replace(trunc(current_date,'MM'),'-','')

 

posted @ 2019-01-15 15:14  wqbin  阅读(396)  评论(0编辑  收藏  举报