title: PostGIS: Spatial Joins Summing using Lats/Lngs
body: <p>I have a table, called <code>pets</code>, with lats and lng coordinates and variables and a table that was created by uploading a shape file, called <code>city</code>, with columns <code>left, right, top, bottom, lat, lng,</code> and  <code>geom.</code> </p>
  
  <pre><code>    lat    lng   cats  dogs
     -99.4   42.1   2     0
     -98.1   44.3   1     1
     -99.7   43.6   0     3 
     -99.8   42.0   2     1
  </code></pre>
  
  <p>I'm wondering how I would construct a query that will sum up the number of cats and dogs within each boundary. Usually I would do a spatial join in QGIS but my dataset is too large and it crashes before successfully joining the two.</p>
  
  <p>I am pretty familiar with QGIS and Postgres, but very new to PostGIS. I've constructed a query but unsuccessful in getting the answer I needed:</p>
  
  <pre><code>select sum(pets.dogs)
  from pets, city
  WHERE ST_Within(pets.dogs, city.geom);
  </code></pre>
  
  <p>Any pointers or resources on PostGIS written for a newbie would be greatly appreciated. Thanks! </p>