title: Arithmetic Operation in a SQL query (nested Select statement) using Python
body: <p>I am trying to do an arithmetic operation in a SQL query using Python (I am using sqlite3).
  My SQL Table (TwTbl) has a coloumn geo_count(number). I have to count the number of entries in which the Geo_count Coloumn has a number greater than 0, and also count the number of entries with Geo_count = 0 and then subtract them. i.e.</p>
  
  <pre><code>(number of entries with Geo_count = 0) - (number of entries with Geo_count &gt; 0)
  </code></pre>
  
  <p>I have to write a nested select statement for that. </p>
  
  <pre><code>import sqlite3
  c.execute("SELECT (COUNT(SELECT geo_count FROM TwTbl WHERE geo_id == 0) – 
            COUNT(SELECT geo_count FROM TwTbl WHERE geo_count IS &lt;&gt; 0)) FROM TwTbl").fetchall()
  </code></pre>
  
  <p>This is giving me a syntax error</p>
  
  <pre><code>Traceback (most recent call last):
     File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  sqlite3.OperationalError: near "SELECT": syntax error
  </code></pre>
  
  <p>I tried writing this query in another way. It is not giving me any syntax error, but not the expected results. If I run the following query I get 0.</p>
  
  <pre><code>c.execute("select count(geo_count) from TwTbl where geo_count == 0 - 
           (select count(geo_count) from TwTbl where geo_count &lt;&gt; 0)").fetchall()
  </code></pre>
  
  <p>Although If I run the queries individually the results are as follows:</p>
  
  <pre><code>c.execute("select count(geo_count) from TwTbl where geo_count &lt;&gt; 0").fetchall()
  &gt;&gt;&gt; 13
  c.execute("select count(geo_count) from TwTbl where geo_count ==0").fetchall()
  &gt;&gt;&gt; 880
  </code></pre>
  
  <p>I am not sure about the correct syntax. Not sure what am I doing wrong. </p>