Return the first day on previous month in Hive

Viewed 37

I try to return the count greater that first day of previous month from column 'dt' in HIVE table.

I use below, and don't work:

select count (*) from my_table 
where dt > from_unixtime(unix_tmestamp(dt,'yyyyMMdd'))```
1 Answers

You can use below code to get first day of previous month based on dt. add_months(trunc(dt,'MM'),-1)

Trunc will truncate date and make it a first day of the month of dt.

Add months will negate 1 month from first day of the month of dt. Screenshot of output. enter image description here

Related