title: Find employee who made highest sales to the customer who made most purchases
body: <p>I'm having trouble with this question in my Database homework And need to answer this question:</p>
  
  <p><strong>Which employee has the highest sales to the customer who has made the most purchases?</strong></p>
  
  <p>And these are my database tables
  <a href="https://i.stack.imgur.com/HujP6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HujP6.png" alt="enter image description here"></a></p>
  
  <p><strong>And these are my attempts to write this query</strong></p>
  
  <pre><code>--select Customers.Firstname,Products.Name,Sales.Quantity from Customers
  --inner join Sales
  --on Customers.CustomerId=Sales.CustomerId
  --inner join Products
  --on Sales.productId=Products.ProductId
  --where Products.Name like 'Mobile'
  
  
  --Select Customers.CustomerId,max(COUNT(Customers.CustomerId)) As Customecount,Emploees.EmploeeId,max(COUNT(Emploees.EmploeeId))as EmploeeeCount from Emploees
  --inner join Sales
  --on Emploees.EmploeeId=Sales.EmploeeId
  --inner join Customers
  --on Customers.CustomerId=Sales.CustomerId
  --group by Customers.CustomerId,Emploees.EmploeeId            ,Count(Sales.productId)as productCount,Count(Emploees.EmploeeId)as emploeeCount,Count(Customers.CustomerId)as customerCount 
  
  select  * from
  (select Distinct Customers.CustomerId,Sales.productId,COUNT(Sales.productId)as CountProduct from Customers
  inner join Sales
  on Customers.CustomerId=Sales.CustomerId
  inner join Emploees
  on Emploees.EmploeeId=Sales.EmploeeId
  group by Sales.productId,Emploees.EmploeeId,Customers.CustomerId,Sales.productId) as Result
  --gr 
  </code></pre>
  
  <p>But these don't work</p>
  
  <p>Please, help me to write this Query.</p>