Skip to content
Advertisement

Sort column values in a particular way

I have 2 tables:

I want to get average of points for each student and each course and sort the result by Student ID and Course in order (Mathematics,Physics and Chemistry).

The output should be the following: For each Student the course order should be (Math,Phys, Chem) and also it should be ordered by Student Name.

How do I achieve the same?

I wrote the following query but not able to sort Course n desired way.

Can someone please help.

Advertisement

Answer

whenever there is a given desired sequence based on some string or some value which can’t be achieved by normal order by asc or order by desc then you need to have your curated ordering by using case when then in your order by clause. Something like this

So your whole query would look like this.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement