title: MySQL groupby with rollup and orderby based on aggregated column
body: <p>I'm trying to do a group by of the amount by each customer_id with 'Total' amount at the end using rollup</p>
  <pre><code>select ifnull(customer_id,'Total') as 'Customer_id'
   ,sum(amount) as 'Amount' 
    from payment 
   group 
      by customer_id with rollup 
   order 
      by customer_id = 'Total'
   , sum(amount) desc;
  </code></pre>
  <p>I have tried using customer_id = 'Total' as suggested in this <a href="https://stackoverflow.com/questions/7673236/sort-after-rollup-preserving-totals-and-subtotals-rows-position">answer</a> but it didn't help.</p>
  <p>I want to sort the data in ascending order based on the sum(amount) value but the 'Total' of all the columns should be the last one.</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: left;">Customer_id</th>
  <th style="text-align: left;">Amount</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: left;">Total</td>
  <td style="text-align: left;">65819.36</td>
  </tr>
  <tr>
  <td style="text-align: left;">15</td>
  <td style="text-align: left;">134.68</td>
  </tr>
  <tr>
  <td style="text-align: left;">16</td>
  <td style="text-align: left;">120.71</td>
  </tr>
  <tr>
  <td style="text-align: left;">17</td>
  <td style="text-align: left;">98.79</td>
  </tr>
  <tr>
  <td style="text-align: left;">18</td>
  <td style="text-align: left;">91.78</td>
  </tr>
  <tr>
  <td style="text-align: left;">19</td>
  <td style="text-align: left;">125.76</td>
  </tr>
  <tr>
  <td style="text-align: left;">20</td>
  <td style="text-align: left;">115.70</td>
  </tr>
  <tr>
  <td style="text-align: left;">21</td>
  <td style="text-align: left;">155.65</td>
  </tr>
  <tr>
  <td style="text-align: left;">22</td>
  <td style="text-align: left;">113.78</td>
  </tr>
  <tr>
  <td style="text-align: left;">23</td>
  <td style="text-align: left;">119.70</td>
  </tr>
  </tbody>
  </table>
  </div>