title: Count number of orders, paymentRatio, return rate and date of last order per customer with MySQL
body: <p>I have a table with the following columns:</p>
  
  <pre><code>|customerNum|OrderNumber|ArticleNumber|PaymentType|Returned?|OrderDate |
  |1          |1          |1            |cash       |Yes      |01.01.2016|
  |2          |2          |3            |credit     |No       |30.02.2016|
  |1          |1          |2            |cash       |No       |01.01.2016|
  |2          |2          |4            |credit     |Yes      |30.02.2016|
  |3          |3          |2            |credit     |No       |17.05.2016|
  |2          |4          |8            |cash       |Yes      |19.08.2016|
  </code></pre>
  
  <p>Expected Outcome:</p>
  
  <pre><code>customerNum|Numb.ofOrdersTot|ratioCash/CreditPayment|returnRate|LastOrder |
  |1         |1               |1                      |0,5       |01.01.2016|
  |2         |2               |0.5                    |0,66      |19.08.2016|
  |3         |1               |0                      |0         |17.05.2016|
  </code></pre>
  
  <p>I want to count the total number of orders (not ordered articles) per customer (one Order can have more than one article), the ratio of cash payment and credit payment (number of cash payments / number of credit payments (one order with more than one article has the same payment method)) the return rate of customer (numberOfReturnedArticles/numberOfArticlesOrderedbycustomerTotal) and last order date</p>
  
  <p>I tried already a part of it already but this is not working and not complete: </p>
  
  <pre><code>`COUNT(*) AS Numb.ofOrdersTot,(COUNT(orderNumber)/COUNT(Returned? = Yes)) FROM table 1 group by customerNum;`
  </code></pre>
  
  <p>PLZ help me: it´s very important :/</p>