title: Execute count(*) on a group-by result-set
body: <p>I am trying to do a nice SQL statement inside a stored procedure.</p>
  
  <p>I looked at the issue of seeing the number of days that events happened between two dates.
  My example is sales orders: for this month, how many days did we have sales orders?</p>
  
  <p>Suppose this setup:</p>
  
  <pre><code>CREATE TABLE  `sandbox`.`orders` (
    `year` int,
    `month` int,
    `day` int,
    `desc` varchar(255) 
  ) 
  
  INSERT INTO orders (year, month, day, desc)  
  VALUES (2009,1,1, 'New Years Resolution 1')
        ,(2009,1,1, 'Promise lose weight')
        ,(2009,1,2, 'Bagel')
        ,(2009,1,12, 'Coffee to go')
  </code></pre>
  
  <p>For this in-data the result should be 3, since there has been three days with sale.
  The best solution I found is as below.</p>
  
  <p>However, making a temporary table, counting that then dropping it seemes excess. It "should" be possible in one statement.</p>
  
  <p>Anyone who got a "nicer" solution then me?</p>
  
  <p>/L</p>
  
  <pre><code>SELECT [Year], [Month], [Day]
  INTO #Some_Days
  FROM Quarter
  WHERE Start &gt;= '2009-01-01' AND [End] &lt; '2009-01-16'
  GROUP BY [Year], [Month], [Day]
  
  SELECT count(*) from #Some_Days
  </code></pre>