title: Count distinct attribute values based on two other columns in SQL
body: <p>I've got a table with three key attributes, like below:</p>
  
  <p><a href="https://i.stack.imgur.com/x4PIE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/x4PIE.png" alt="Input Table"></a></p>
  
  <p>I want to query it to figure out the number of items sold based on item type and date sold. So the output might look something like this:</p>
  
  <p><a href="https://i.stack.imgur.com/27glz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/27glz.png" alt="http://i.stack.imgur.com/27glz.png"></a></p>
  
  <p>My query looks like this:</p>
  
  <pre><code>SELECT SaleItem AS 'Item Sold', SaleDay AS 'Item Sell Day', COUNT(DISTINCT SaleNumber) AS 'Number'
  FROM Sales
  GROUP BY SaleDay, SaleItem
  </code></pre>
  
  <p>This is returning a table with the SaleItems organized properly, but the count is the total number sold, excluding the SaleDay attribute.</p>
  
  <p>It's returning the total number of sales per item instead of only the sales on that day per item. So, if 7 pens were sold Monday and 6 on Tuesday it should return two tuples (7, Monday, Pen) and (6, Tuesday, pen). Currently, its returning (13, Monday, pen) and (13, Tuesday, pen).</p>
  
  <p>How can I fix this query?</p>