title: Hive- Error : missing EOF at 'WHERE'
body: <p>I'm trying to learn Hive, especially functions like <code>unix_timestamp</code> and <code>from_unixtime</code>. </p>
  
  <p>I have three tables </p>
  
  <pre><code>emp (employee table)
  +---+----------------+
  | id|            name|
  +---+----------------+
  |  1|    James Gordon|
  |  2|  Harvey Bullock|
  |  3| Kristen Kringle|
  +---+----------------+
  
  txn (transaction table)
  +------+----------+---------+
  |acc_id|trans_date|trans_amt|
  +------+----------+---------+
  |   101|  20180105|      951|
  |   102|  20180205|      800|
  |   103|  20180131|      100|
  |   101|  20180112|       50|
  |   102|  20180126|      800|
  |   103|  20180203|      500|
  +------+----------+---------+
  
  acc (account table)
  +---+------+--------+
  | id|acc_id|cred_lim|
  +---+------+--------+
  |  1|   101|    1000|
  |  2|   102|    1500|
  |  3|   103|     800|
  +---+------+--------+
  </code></pre>
  
  <p>I want to find out the people whose <code>trans_amt</code> exceeded their <code>cred_lim</code> in the month of Jan 2018.</p>
  
  <p>The query I'm trying to use is</p>
  
  <pre><code>WITH tabl as
  (
  SELECT  e.id, e.name, a.acc_id, t.trans_amt, a.cred_lim, from_unixtime(unix_timestamp(t.trans_date, 'yyyyMMdd'), 'MMM yyyy') month
  FROM emp e JOIN acc a on e.id = a.id JOIN txn t on a.acc_id = t.acc_id
  )
  SELECT acc_id, sum(trans_amt) total_amt
  FROM tabl
  GROUP BY tabl.acc_id, tabl.month
  WHERE tabl.month = 'Jan 2018' AND tabl.total_amt &gt; cred_lim;
  </code></pre>
  
  <p>But when I run it, I get an error saying</p>
  
  <pre><code>FAILED: ParseException line 9:2 missing EOF at 'WHERE' near 'month'
  </code></pre>
  
  <p>This error persists even when I change the where clause to</p>
  
  <pre><code>WHERE tabl.total_amt &gt; cred_lim;
  </code></pre>
  
  <p>This makes me think the error comes from the <code>GROUP BY</code> clause but I can't seem to figure this out.</p>
  
  <p>Could someone help me with this?</p>