Reputation: 648
Okay, this should be a fairly easy question I think, but haven't been able to figure it out yet.
I have a table entitled Staff. The staff DESC is below:
SQL> DESC Staff
Name Null? Type
----------------------------------------- -------- ----------
SNO NOT NULL CHAR(5)
FNAME VARCHAR2(3
LNAME VARCHAR2(3
POSITION VARCHAR2(1
SEX CHAR(1)
DOB DATE
SALARY NUMBER(9)
BNO CHAR(4)
Here is the current query I am using:
SELECT bNo, lName||' '||fName, position, salary
FROM Staff
WHERE bNo 'b009'
OR bNo = 'b005'
ORDER BY
case position
when 'Manager' then 1
when 'Secretary' then 2
when 'Supervisor' then 3
when 'Assistant' then 4
else 99
end;
The problem I am having is that within each position group, I need to sort by lName as well. Any tips would be greatly appreciated. Thanks in advance.
Upvotes: 2
Views: 432
Reputation: 453287
Just add lName
as a second ORDER BY
column.
ORDER BY CASE position
WHEN 'Manager' THEN 1
WHEN 'Secretary' THEN 2
WHEN 'Supervisor' THEN 3
WHEN 'Assistant' THEN 4
ELSE 99
END,
lName;
Upvotes: 6