title: I am getting the Error "ERROR: column "distance" does not exist LINE 2: FROM "gps" WHERE distance < 30 ; "
body: <p>I have this piece of SQL code:</p>
  
  <pre><code> create table gps(id integer, latitude double, longitude double);
  insert into gps(id, latitude, longitude) values(1, 2, 3);
  insert into gps(id, latitude, longitude) values(1, 1, 1);
  insert into gps(id, latitude, longitude) values(1, 1, 1);
  insert into gps(id, latitude, longitude) values(1, 30, 1);
  </code></pre>
  
  <p>but i noticed the code runs fine on MYSQL, but throws an error on postgres.</p>
  
  <pre><code> ERROR:  column "distance" does not exist
  LINE 6: HAVING  distance &lt; 30
  </code></pre>
  
  <p>an alternative would be</p>
  
  <pre><code>SELECT * , latitude + longitude AS distance
  FROM "gps"
  GROUP BY id
  HAVING  latitude + longitude &lt; 30
  </code></pre>
  
  <p>but this can get messy specially if the code is longer that latitude + longitude</p>
  
  <p>I have looked for a way to by pass this but with no solution</p>