title: Query to order by the last three characters of a column
body: <p>Query the name of any student in STUDENTS who scored higher than 75 marks. Order your output by the last three characters of each name. If two or more students both have names ending in the same last three characters (i.e.: &quot;Bobby&quot;, &quot;Robby&quot;, etc.), secondary sort them by ascending ID.</p>
  <p>STUDENTS table has following columns:</p>
  <p><code>ID , NAME , MARKS</code></p>
  <p>Sample input:</p>
  <pre><code>id         name     marks
  1          ashley   81
  2          samantha 75
  3          julia    76
  4          belvet   84
  </code></pre>
  <p>Sample output:</p>
  <pre><code>Ashley
  Julia
  Belvet
  </code></pre>
  <p>Explanation:</p>
  <p>Only Ashley, Julia, and Belvet have <code>marks &gt; 75</code>. If you look at the last three characters of each of their names, there are no duplicates and <code>'ley' &lt; 'lia' &lt; 'vet'</code>.</p>
  <p>This is correct output:</p>
  <blockquote>
  <p>select name from students where marks&gt;75</p>
  <p>order by substr(name, -3, 3), id;</p>
  </blockquote>