我正在尝试从特定月份获取一组月份值。例如-如果我的开始日期是2011-11-05,那么我想设置从2011-11到今天的月份(即2018-05)。
It should look like this... 2011-11 2011-12 2012-01 2012-02 . . . . 2015-01 . . 2018-04 2018-05
我需要将此设置为Map每个月的活动/非活动用户
wnvonmuf1#
请尝试以下代码:
select s.country,date_format(days_list,'YYYYMM') as year_month_list from ( select x.country,date_add (x.start_date,y.i) as days_list from (select 'Inida' as country, current_timestamp end_date,'2011-11-05' as start_date) x lateral view posexplode(split(space(datediff(x.end_date,x.start_date)),' ')) y as i,k ) s group by s.country,date_format(days_list,'YYYYMM'); Total MapReduce CPU Time Spent: 0 msec OK Inida 201111 Inida 201112 Inida 201201 Inida 201202 Inida 201203 Inida 201204 Inida 201205 Inida 201206 Inida 201207 Inida 201208 Inida 201209 Inida 201210 Inida 201211 Inida 201212 Inida 201301 Inida 201302 Inida 201303 Inida 201304 Inida 201305 Inida 201306 Inida 201307 Inida 201308 Inida 201309 Inida 201310 Inida 201311 Inida 201312 Inida 201401 Inida 201402 Inida 201403 Inida 201404 Inida 201405 Inida 201406 Inida 201407 Inida 201408 Inida 201409 Inida 201410 Inida 201411 Inida 201412 Inida 201501 Inida 201502 Inida 201503 Inida 201504 Inida 201505 Inida 201506 Inida 201507 Inida 201508 Inida 201509 Inida 201510 Inida 201511 Inida 201512 Inida 201601 Inida 201602 Inida 201603 Inida 201604 Inida 201605 Inida 201606 Inida 201607 Inida 201608 Inida 201609 Inida 201610 Inida 201611 Inida 201612 Inida 201701 Inida 201702 Inida 201703 Inida 201704 Inida 201705 Inida 201706 Inida 201707 Inida 201708 Inida 201709 Inida 201710 Inida 201711 Inida 201712 Inida 201801 Inida 201802 Inida 201803 Inida 201804 Inida 201805 Inida 201812 Time taken: 2.184 seconds, Fetched: 80 row(s)
1条答案
按热度按时间wnvonmuf1#
请尝试以下代码: