title: How to group by 3 columns -and- get a count in SQL Server?
body: <p>I'm trying to create some SQL that groups by three columns and then gets the <code>COUNT</code> of those rows that form that grouped result.</p>
  
  <p>Also, ordered by the highest count, first. </p>
  
  <p><a href="http://sqlfiddle.com/#!6/41c33/3" rel="nofollow">I've created a SqlFiddle</a> to help me.</p>
  
  <p>Table schema (simplified):</p>
  
  <pre><code>CREATE TABLE [dbo].[Foo]
  (
      [FooId] [int] IDENTITY(1,1) NOT NULL,
      [CreatedOn] [datetime] NOT NULL,
      [Company] [varchar](20) NOT NULL,
      [ProductFirstname] [varchar](100) NOT NULL,
      [ProductLastname] [varchar](100) NOT NULL
  )
  </code></pre>
  
  <p>Sample data:</p>
  
  <pre><code>INSERT INTO Foo VALUES ('2001-10-01T07:07:07', 'Red', 'Yummy', 'GummyBear');
  INSERT INTO Foo VALUES ('2002-10-01T07:07:07', 'Red', 'Yummy', 'GummyBear');
  INSERT INTO Foo VALUES ('2003-10-01T07:07:07', 'Red', 'Bannana', 'Cake');
  INSERT INTO Foo VALUES ('2003-11-11T07:07:07', 'Red', 'Green', 'Apples');
  INSERT INTO Foo VALUES ('2004-10-01T07:07:07', 'Red', 'Yummy', 'GummyBear');
  INSERT INTO Foo VALUES ('2005-10-01T07:07:07', 'Blue', 'Yummy', 'GummyBear');
  INSERT INTO Foo VALUES ('2006-10-01T07:07:07', 'Blue', 'Yummy', 'GummyBear');
  INSERT INTO Foo VALUES ('2007-10-01T07:07:07', 'Blue', 'Yummy', 'GummyBear');
  INSERT INTO Foo VALUES ('2008-10-01T07:07:07', 'Red', 'Yummy', 'GummyBear');
  INSERT INTO Foo VALUES ('2009-10-01T07:07:07', 'Blue', 'Green', 'Apples');
  </code></pre>
  
  <p>Expected result:</p>
  
  <pre><code>+-----------------------------------+
  | Company | Name            | Count |
  +-----------------------------------+
  |    Red   | Yummy GummyBear | 4    |
  |   Blue   | Yummy GummyBear | 3    |
  |    Red   | Bannana Cake    | 1    |
  |    Red   | Green Apples    | 1    |
  |   Blue   | Green Apples    | 1    |
  +-----------------------------------+
  </code></pre>
  
  <p>So with this data, <code>CreatedOn</code> is basically ignored. It's some meta data for another use.</p>