title: SQL Divide by Two Count()
body: <p>I have the following query, which is trying to figure out the percentage of a certain product compared to the total number of products. IE: [Product Count] / [Total Products] = Percent</p>
  
  <pre><code>;WITH totalCount AS(
      SELECT 
          CAST(COUNT(id) as Integer)as totalCount
      FROM TABLE_NAME
  )
  SELECT 
      ((CAST(COUNT(DISTINCT id) as Integer)/(SELECT * FROM totalCount))*100) as 'Percent'
  FROM TABLE_NAME
  </code></pre>
  
  <p>However, the percent column always returns "0" unless there is only one record. In addition, is there a way to add the totalCount and Select query into one?</p>
  
  <p>Basically, how do you divide two Count() fields?</p>