title: SemanticException [Error 10004]: Line 11:18 Invalid table alias or column reference
body: <p>This question is related to the answer of <a href="https://stackoverflow.com/questions/45481288/how-to-retrieve-trips-from-historical-data/45483836?noredirect=1#comment77933116_45483836">my previous question</a>. Please notice that <code>datetime</code> is string. Therefore I convert it to unix timestamp.</p>
  
  <p>I execute this query in Hive 1.2.1:</p>
  
  <pre><code>select count(*) / count(distinct to_date(datetime)) as trips_per_day 
  
  from (select radar_id,to_unix_timestamp(datetime),lead(radar_id) over w as 
        next_radar_id,lead(to_unix_timestamp(datetime)) over w as 
        next_datetime 
        from mytable 
        where radar_id in ('A21','B15') window w as 
       (partition by car_id order by to_unix_timestamp(datetime))) t 
  
  where radar_id = 'A21' and next_radar_id = 'B15' 
        and to_unix_timestamp(datetime) + 30*60 &gt; to_unix_timestamp(next_datetime);
  </code></pre>
  
  <p>But I get the following error:</p>
  
  <blockquote>
    <p>SemanticException [Error 10004]: Line 11:18 Invalid table alias or
    column reference 'datetime': (possible column names are: radar_id, _c1,
    next_radar_id, next_datetime)</p>
  </blockquote>
  
  <p>Where is an error?</p>