Sorting Columns in a Grid When Order isn't Clear

Suppose I query a database table for some data and display it in a table where I can set the sorting of each column. Here are three scenarios where the data either doesn't have an obvious order, or what we display is not in the database:

Case 1: Suppose we store usernames and not full names, but we only display full names in the table. Is there an easy way of being able to sort the table based on the full name without having to also save the full name in the database?

Case 2: Supposed we store two numerical values x and y in the database, and we display x/y. How can I sort by the value of x/y?

Case 3: Suppose that we have some text values each associated with an id, but that the id (for whatever reasons) cannot be used to order the text by significance. Is there a way to sort the text in some predetermined but custom order, without having to save information in the database about what this custom order is?

  Discussion posts and replies are publicly visible