title: SQL / Presto error: TYPE_MISMATCH:Left side of logical expression must evaluate to a boolean (actual: varchar)
body: <p>I'm trying to match all active <em><strong>subscription</strong></em> statuses with shipping data from the <em><strong>customers</strong></em> table with the total charges &amp; refunds from the <em><strong>charges</strong></em> table.<br />
  The error is from lines 29:88, or the 2nd &quot;group by&quot; after c.shipping_address_city. This issue does not occur with the first &quot;group by&quot; part of the query, which I copied &amp; pasted into the second select statement.
  When I got reduced the &quot;group by&quot; fields to only c.email or. c.id, I got an aggregate error:</p>
  <pre><code>active_customer_plans as (
  
    select c.email, c.id as customer_id, c.shipping_name, c.name, c.shipping_address_line1, c.shipping_address_line2, 
      c.shipping_address_city, c.shipping_address_state, c.shipping_address_postal_code, c.shipping_address_country, sum(charges.amount) as total_charges, 
      sum(charges.amount_refunded) as total_refunds
    from subscriptions sub
      left join charges on sub.customer_id = charges.customer_id
      left join customers c on sub.customer_id = c.id
    where sub.status in ('active', 'past_due')
    group by c.email, c.id, c.shipping_name, c.name, c.shipping_address_line1, c.shipping_address_line2, 
      c.shipping_address_city, c.shipping_address_state, c.shipping_address_postal_code, c.shipping_address_country
    
  
    union all
  
    -- including subscriptions migrated from vhx existing as trialing
    -- and excluding paused subscriptions
    select c.email, c.id as customer_id, c.shipping_name, c.name, c.shipping_address_line1, c.shipping_address_line2, 
      c.shipping_address_city, c.shipping_address_state, c.shipping_address_postal_code, c.shipping_address_country, sum(charges.amount) as total_charges,
      sum(charges.amount_refunded) as total_refunds, 'active (migrated_trialing)' as status
    from subscriptions sub
      left join charges on sub.customer_id = charges.customer_id
      left join customers c on sub.customer_id = c.id
    where sub.status in ('trialing')
    group by c.email, c.id, c.shipping_name, c.name, c.shipping_address_line1, c.shipping_address_line2, 
       c.shipping_address_city, c.shipping_address_state, c.shipping_address_postal_code, c.shipping_address_country
    
      and exists (
        select sub_meta.subscription_id
        from subscriptions_metadata sub_meta
        where sub.id = sub_meta.subscription_id
          and sub_meta.key = 'zype_migration'
          and sub_meta.value = 'true'
      )
      and not exists (
        select sub_meta.subscription_id
        from subscriptions_metadata sub_meta
        where sub.id = sub_meta.subscription_id
          and sub_meta.key = 'zype_status'
          and sub_meta.value = 'paused'
      )
  
  
    -- excluding subscriptions migrated from vhx existing as trialing
    -- and excluding paused subscriptions
  
  )
  select status as subscription_status,
      email as customer_email,
    customer_id,
    shipping_name,
    name,
    shipping_address_line1,
    shipping_address_line2,
    shipping_address_city,
    shipping_address_state,
    shipping_address_postal_code,
    shipping_address_country,
    total_charges,
    total_refunds
  from active_customer_plans
  
  order by 1, 2
  </code></pre>