title: Error #1111 - Invalid use of group function
body: <p>EDIT - I am working in XAMPP</p>
  
  <p>I'm doing a homework for school, and this is the database I'm given:</p>
  
  <p><code>customers(customerName, city, customerNumber)</code></p>
  
  <p><code>orders(customerNumber, orderNumber)</code></p>
  
  <p><code>orderdetails(orderNumber, priceEach, quantityOrdered)</code></p>
  
  <p>and I'm trying to query for the name of the customer who has placed the biggest order by total value (priceEach*quantityOrdered), and it's a requirement for me to use at least one nested query.</p>
  
  <p>Here is what I <em>believe</em> should be the right answer:</p>
  
  <pre><code>SELECT customername
  FROM orderdetails 
  INNER JOIN orders
  on orderdetails.orderNumber = orders.orderNumber
  INNER JOIN customers
  on orders.customerNumber = customers.customerNumber
  WHERE sum(priceEach*quantityOrdered) = (SELECT 
      max(sum(priceEach*quantityOrdered))
      FROM orderdetails
      INNER JOIN orders
      on orderdetails.orderNumber = orders.orderNumber
      INNER JOIN customers
      on orders.customerNumber = customers.customerNumber
      GROUP by orderdetails.orderNumber)
  GROUP by orderdetails.orderNumber
  ORDER by sum(priceEach*quantityOrdered) DESC
  </code></pre>
  
  <p>However, when I enter it, I get an error "#1111 - Invalid use of group function" and I can't for the life of me figure out why.  Thanks</p>
  
  <p>EDIT - even when I remove all the GROUP BY and ORDER BY lines from the query, I still receive the same error.  I <em>think</em> it has to do with me calling 'max' and 'sum' in the nested query SELECT but I am not totally sure.</p>