title: Unknown Column Haversine Query with Column created as Query runs
body: <p>I have a table of results that looks like this (there is only 1 result at the moment):
  <img src="https://i.stack.imgur.com/zaB97.png" alt="enter image description here"></p>
  
  <p>Here is my query that produces that result:</p>
  
  <pre><code>SELECT DISTINCT 
  ID, post_author, post_title, post_type, post_status,
  max(CASE WHEN escort_details.`meta_key` = 'longitude' THEN
  escort_details.meta_value END) AS longitude,
  max(CASE WHEN escort_details.`meta_key` = 'latitude' THEN
  escort_details.meta_value END) AS latitude
  FROM wp_posts as escorts 
  INNER JOIN wp_postmeta as escort_details
  WHERE escorts.post_type = 'escorts'
  AND escorts.post_status = 'publish'
  </code></pre>
  
  <p>I'm creating the longitude and latitude columns as the query is run but I want to search those columns and return the distance with the other part of my query which is the haversine part.</p>
  
  <p>So my full query now looks like this:</p>
  
  <pre><code>SELECT DISTINCT 
  ID, post_author, post_title, post_type, post_status,
  max(CASE WHEN escort_details.`meta_key` = 'longitude' THEN
  escort_details.meta_value END) AS longitude,
  max(CASE WHEN escort_details.`meta_key` = 'latitude' THEN
  escort_details.meta_value END) AS latitude,
  ( 3959 * acos( cos( radians("121.184006") ) * cos( radians( latitude ) ) 
  * cos( radians( longitude ) - radians("14.817371") )
  + sin( radians("121.184006") ) * sin(radians(latitude)) ) ) AS distance
  FROM wp_posts as escorts 
  INNER JOIN wp_postmeta as escort_details
  WHERE escorts.post_type = 'escorts'
  AND escorts.post_status = 'publish'
  </code></pre>
  
  <p>The error I am receiving back is "Unknown column 'longitude' in 'field list'" which would make sense as there isn't really a longitude field in the database as it sort of gets created as the query is run.</p>
  
  <p>I'm wondering if anyone knows of a way to combat this? </p>
  
  <p>As always any help is appreciated.</p>
  
  <p>Thanks,
  Codarz360</p>