Views Sort Expression

Introduction

Views Sort Expression allows you to add an SQL expression as a sort handler in your View. This is an advanced module that requires knowledge of SQL and how to construct expression-based ORDER BYs.

It aims to be a helper module to achieve custom ordering that is normally not possible with the regular sort handlers or that are not covered by existing modules.

By sorting by an expression you can do things like showing NULL items last when sorting by a numeric field, or creating a custom sort order putting some content types on top. The possibilities are endless.

You may use whatever is you have currently available on the query. For that reason you should always enable the "Show the SQL query" on the Views's setting page. Normally, adding a field or the like doesn't necessarily add to the SQL query, so you may find useful adding whatever is you want to use and inside the expression as a sort in the end, and put your expression where you need it.

views_sort_expression
Module