Postgres: Order by Non Zeros ASC followed by Zeros and then NULLS LAST
<p>I have a PG database table <strong>prices</strong>. The structure is as below:</p>

<pre><code>id    name    total_sales    created_at
1      A         0.0         2016-01-01
2      B         1.25        2016-01-01
3      C         8.17        2016-01-01
4      D         15.09       2016-01-01
5      E         0.0         2016-01-01
6      F         NULL        2016-01-01
7      G         2.25        2016-01-01
8      H         19.34       2016-01-01
9      I         47.91       2016-01-01
10     J         0.0         2016-01-01
11     K         NULL        2016-01-01
12     L         0.01        2016-01-01
13     M         5.11        2016-01-01
14     N         27.53       2016-01-01
15     O         3.53        2016-01-01
</code></pre>

<p>What I need is very simple. I would like to order the records such that:</p>

<p><strong>Items with values > 0.0 in ASCENDING order comes first</strong> followed by
<strong>Items with 0.0 and then NULLS LAST</strong></p>

<p>In short, I would need the o/p in below sequence:</p>

<pre><code>1st: 12 =&gt; 0.01
2nd: 2 =&gt; 1.25,
3rd: 7 =&gt; 2.25,
4th: 15 =&gt; 3.53,
5th: 13 =&gt; 5.11,
6th: 3 =&gt; 8.17,
7th: 4 =&gt; 15.09,
8th: 8 =&gt; 19.34,
9th: 14 =&gt; 27.53,
10th: 9 =&gt; 47.91,
11th, 12th, 13th all 0.0
14th, 15th all NULLS
</code></pre>

<p>So, far I tried below SQLs but none worked!</p>

<pre><code>SELECT * FROM prices
ORDER BY CASE WHEN total_sales = 0.0 THEN 0 ELSE total_sales END ASC NULLS LAST
</code></pre>