mysql - Query to order by the last three characters of a column -


query name of student in students scored higher 75 marks. order output last 3 characters of each name. if 2 or more students both have names ending in same last 3 characters (i.e.: bobby, robby, etc.), secondary sort them ascending id.

students table has following columns

id , name , marks

sample input

id         name     marks 1          ashley   81 2          samantha 75 3          julia    76 4          belvet   84 

sample output

ashley julia belvet 

explanation

only ashley, julia, , belvet have marks > 75. if @ last 3 characters of each of names, there no duplicates , 'ley' < 'lia' < 'vet'.

i tried

select distinct name  students  marks > 75  order right(name,3),id;  

but it's not working.

try mysql:

select name students marks > 75 order right(name, 3), id 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -