title: SQL count one row if many exist
body: <p>I have what I think is a pretty standard Postgres SQL problem. I can explain it, just can't program it.</p>
  
  <p>I have 4 rows that have unique account IDs. Each of these rows shares the same longitude and latitude values, but their physical addresses differ (apartment 1A, apartment 2B.....). Each account has status of active or inactive. Each account either gets or does not get HBO.</p>
  
  <p>This data is all derived from a single table. My condition is this: 
  Grouping by latitude, longitude and the name of the borough, loop the data and count one row where every account is inactive and at least one of the accounts is still getting HBO.</p>
  
  <p>So if there are 4 accounts at the same lng/lat, 3 are inactive but 1 is still active, the record is <strong>skipped</strong>.</p>
  
  <p>If there are 4 accounts at the same lng/lat, 4 are inactive, none get HBO, the record is <strong>skipped</strong>.</p>
  
  <p>If there are 4 accounts at the same lng/lat, 4 are inactive, one still gets HBO, the record is <strong>counted</strong>.</p>
  
  <p>UPDATE:
  I need this as a count by town. I just used the lat/lng to confirm that the logic was correct and it is. The final result I'm looking for is this:</p>
  
  <pre><code>Borough | Count
  ---------------------
  Bronx      50
  Queens     12
  </code></pre>