Это можно сделать несколькими способами. Два метода:
select last_day(printf('%04d-%02d-%02d',year(current_date),(month(current_date)-1) div 3 * 3 ,1));
Возвращает:
2019-03-31
Проверено здесь: http://demo.gethue.com/hue/editor?editor=326549
Еще один метод:
select last_day(concat(year(current_date),'-',lpad((month(current_date)-1) div 3 * 3,2,0) ,'-01'))
Тест: http://demo.gethue.com/hue/editor?editor=326554
Важные версии, обратите внимание: В старых версиях Hive current_date
может не работать, вместо этого используйте unix_timestamp()
:
select last_day(concat(year(current_timestamp()),'-',lpad((month(current_timestamp())-1) div 3 * 3,2,0) ,'-01'))
Тест: http://demo.gethue.com/hue/editor?editor=326565
Прочитайте руководство и придумайте свой собственный метод.