How to sort a view so that, say, all the nodes with stock=0 come last, and not sort by stock? I want to sort an output of a view so that the elements with a filed value of "0" be at the end of the list, but all the others are to be treated equally. In fact, it's an Drupal Commerce site, and I want all products with stock >0 to appear first in the lists, regardless of the stock quantity, so that the unavailable stuff get at the end, but still be in the view (after that, I sort alphabeitcally). 
Any ideas how to do that? 
That means making the output of a boolean forumla stock=0 the sorting criterion
You could do this if you use something like the Views php module, because that will allow you to use php code to sort by.  I know that module is currently looking for additional maintainers, I just can't think of an alternative.

Once you've enabled it, and added a php field to sort by, I'd have it return something like:

min([commerce_stock], 1);  // replace [commerce_stock] with whatever your available stock variable is.


What that code will do is return 1 (the minimum) if you have any stock more than 1, but it will return 0 if the product is all out.

So it will only return 1 (there are items) or 0 (there are none), which is exactly what you want.  Next, you can add a sort by name or whatever you want to sort these two groups further.

Let us know if it works.  I was having a bit of problems getting this rolling, since my stock variable is just returning my product ID, and I'm not sure if I'm just running slightly out-of-date modules or what.  So let us know if a similar approach works when you try it!!