I want to order by a column name that has values like "Value1" Space "Value2" in the same column. Eg.
Column1 |
---|
Value1 value2 |
NSPP02 2111 |
NSPP02 2110 |
NSPP01 2111 |
I want to order it by value2 first and then by value1. ASC by value 2 and then ASC by Value 1.
I am using aggregate as follows:
select
pdc.semester as Semester,
count(pdc.CNIC) as TotalRegistrations,
count(s.studentid) as TotalRegistered,
count(case when r.Grade is not null then 'Appeared' end) as Appeared,
count(case when r.Grade='f' then 'fail' end) as Failed,
count(case when r.grade <>'f' then 'pass' end) as Passed
from
PDC_PreRegistration pdc
left join
Students s on pdc.Semester = s.CurSemester and s.nic = pdc.CNIC
left join
studentresultnet r on s.studentid = r.studentid and s.CurSemester = r.Semester
left join
semester se on se.Semester = r.Semester
where
pdc.semester in (select CurSemester from students where batch = 'PD2110')
group by
pdc.Semester
order by
semester desc
The result of this query is the following:
Semester | TotalRegistrations | TotalRegistered | Appeared | Failed | Passed |
---|---|---|---|---|---|
NSPP02 2111 | 121 | 81 | 0 | 0 | 0 |
NSPP02 2110 | 37 | 35 | 24 | 1 | 23 |
NSPP01 2111 | 76 | 42 | 0 | 0 | 0 |
I want the result to be like this:
Semester | TotalRegistrations | TotalRegistered | Appeared | Failed | Passed |
---|---|---|---|---|---|
NSPP02 2110 | 37 | 35 | 24 | 1 | 23 |
NSPP01 2111 | 76 | 42 | 0 | 0 | 0 |
NSPP02 2111 | 121 | 81 | 0 | 0 | 0 |
ASC by value 2 and then ASC by Value 1.
Example sequence of semester column is like below:
- NSPP01 2110
- NSPP02 2110
- NSPP01 2111
- NSPP02 2111
- NSPP01 2112
- NSPP02 2112
- NSPP01 2201
- NSPP02 2201
- NSPP01 2202
- NSPP02 2202
- NSPP01 2203
- NSPP02 2203
- and so on
Check this screenshot: