title: Not getting correct count on OrderID
body: <p>My Sample data</p>
  
  <pre><code>EmailAddress   CustomerID OrderID OrderDate
  XYZ@gmail.com   123454    1244     04/11/2018
  XYZ@gmail.com   123466    1249     04/15/2018  
  </code></pre>
  
  <p>My data is unique only by emailaddress.
  I have a SQL Query where Customers,Orders and Orderdetails table are involved. I am trying to get total_ordered by customer but it is not giving me right results. But when i remove orderdetails table from my query i get count right . I am not understanding why it is happening.  I want Total_Ordered column to be calculated correctly. Right now it is doubling the purchases by a customer. Any help is appreciated.</p>
  
  <pre><code>SELECT
  Customers.EmailAddress,
  COUNT(Orders.OrderID) as Total_Ordered,
  COUNT(CASE WHEN od.ProductCode LIKE 'DSC%' THEN  od.ProductCode END ) as DscoRDERS
  FROM Orders 
  JOIN (
        SELECT
           Orderid,
            ProductCode
        FROM OrderDetails
        GROUP BY
  OrderID,
        ProductCode
  ) od ON Orders.Orderid = od.Orderid
  JOIN Customers ON Customers.Customerid = Orders.Customerid
  WHERE
  Orders.OrderDate BETWEEN ' 01/01/2018 00:00' AND GETDATE()
  GROUP BY
  Customers.EmailAddress
  </code></pre>