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.: "Bobby", "Robby", etc.), secondary sort them by 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, and Belvet have marks > 75
. If you look at the last three characters of each of their names, there are no duplicates and 'ley' < 'lia' < 'vet'
.
This is correct output:
select name from students where marks>75
order by substr(name, -3, 3), id;
RIGHT()
is a MySQL function but not an Oracle RDBMS function. Maybe that's why it's not working. So (1) please clarify your question's tags and (2) explain how the query is not working, for instance by posting the error message you get or by describing the observed behaviour – APC Jan 17 '16 at 14:27