title: How to get last one month's data from a table based on current month and year?
body: <p>I am facing some problem with the hive code. 
  My <code>FROM TABLE</code> is partitioned based on month, year and day. I came up with the following code to get the data I need. The logic is something like if the current <code>mth</code> is <code>01</code> then change the <code>month</code> to 12 and the year to <code>yr - 1</code>
  else change month to <code>mth - 1</code> and keep the year as is.</p>
  
  <pre><code>set hivevar:yr=2019;
  set hivevar:mth=03;
  set hivevar:dy=29;
  
  SELECT * from 
  FROM table
  WHERE 
  month = case when cast('${mth}' as int) = 01 then 12 else cast((cast('${mth}' as int) - 1) as string) end
  AND year = case when cast('${mth}' as int) = 01 then cast((cast('${yr}' as int) - 1) as string) else '${yr}' end;
  </code></pre>
  
  <p>It is not working, my <code>select *</code> is coming empty. Please help.</p>
  
  <p><code>desc table</code>
  <a href="https://i.stack.imgur.com/bSraF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bSraF.png" alt="table"></a></p>