title: MySQL: Find out which store customer spent most money in
body: <p>Making an automated call list to be generated based on certain search criteria that pulls customers names and phone numbers.</p>
  
  <p>There are 4 tables: Customer, Phone_Numbers, Sales_Header, Sales_Detail.</p>
  
  <p>The query is as follows:</p>
  
  <pre><code>SELECT CONCAT(customer.First_Name, ‘’, customer.Last_Name), 
         Phone_Numbers.Number, 
         Customer.ID 
  FROM Sales_Header 
  INNER JOIN Sales_Detail ON Sales_Detail.Header_ID = Sales_Header.ID 
  INNER JOIN Customer ON Customer.ID = Sales_Header.Customer_ID 
  INNER JOIN Phone_Numbers ON Phone_Numbers.Customer_ID = Customer.ID 
  WHERE Sales_Header.WebSale = -1 
    AND Sales_Detail.Price &gt; 1000 
    AND DateSold &gt; 20081002
  </code></pre>
  
  <p><strong>Question:</strong></p>
  
  <p>Each sale in the sales_header has a store location (ID for which store it was sold at).
  However customers can buy from more than one store. I need to find out which store the customer spent the most money in, and add that store to the select statement output above.</p>