title: How to write this MySQL query in Hive
body: <p>I am getting syntax error while querying into HIVE metastore</p>
  <p>I am checking if current_date data exists then group by based on this date or else take input from user then group by</p>
  <p>MYSQL equivalent</p>
  <pre><code>IF  EXISTS (SELECT 1 from dbo.table  where campaign_date = current_date)
      begin
          SELECT   flag as ID,
    count(*) as count
    FROM dbo.table 
    where campaign_date=cast(getdate() as date) group by 1
      end
  else    
      begin
          SELECT   flag as ID,
    count(*) as count
    FROM  dbo.table
    where campaign_date=  '{{ campaign_date }}'   group by 1
      end
  </code></pre>
  <p>I wrote this in HiveQL</p>
  <pre><code>select count(1) as count_var FROM
  dbo.table  where campaign_date = current_date;
  
  if (count_var=0){
  
  SELECT   flag as ID,
    count(*) as count
    FROM dbo.table
    where campaign_date = '{{ campaign_date }}'   group by 1
    
    
  }else {
  SELECT   flag as ID,
    count(*) as count
    FROM dbo.table
    where campaign_date=  current_date   group by 1}
  </code></pre>
  <p>I am getting this error</p>
  <pre><code>Extraneous input 'if' expecting ...
  </code></pre>