title: How to count 2 different data in one query
body: <p>I need to calculate sum of occurences of some data in two columns in one query. DB is in SQL Server 2005.  </p>
  
  <p>For example I have this table:</p>
  
  <pre><code>Person: Id, Name, Age
  </code></pre>
  
  <p>And I need to get in one query those results:<br>
  1. Count of Persons that have name 'John'<br>
  2. Count of 'John' with age more than 30 y.</p>
  
  <p>I can do that with subqueries in this way (it is only example):</p>
  
  <pre><code>SELECT (SELECT COUNT(Id) FROM Persons WHERE Name = 'John'), 
    (SELECT COUNT (Id) FROM Persons WHERE Name = 'John' AND age &gt; 30) 
  FROM Persons
  </code></pre>
  
  <p>But this is very slow, and I'm searching for faster method. </p>
  
  <p>I found this <a href="https://stackoverflow.com/questions/5133388/is-it-possible-to-count-two-columns-in-the-same-query">solution</a> for MySQL (it almost solve my problem, but it is not for SQL Server).</p>
  
  <p>Do you know better way to calculate few counts in one query than using subqueries?</p>