Since department code pattern looks to be convenient, I didn't spent time on parent_id. According to your department code pattern, following should help.
Simply padding the dept code and getting the sortable uniform codes.
Change your tableName in query please.
SELECT *
FROM tableName
ORDER BY RPAD(dept_code, 5, '0')
EDIT: Actually if parent_deptid was the actual parent's id then you would have just needed to sort by parent_deptid, then dept_code. However, parent_deptid doesn't look like the corresponding parent's id but something like "depth" instead.
EDIT2: Sorry, your parent_deptid looks to be ok, just needed to see more data showing other parent ids too. So I missed it. All you need to sort as following:
SELECT *
FROM tableName
ORDER BY parent_deptid, dept_code;
EDIT3 - According to edited question: Back to my initial suggestion by changing the padded string length - Following is the most suitable solution for your data structure.
SELECT *
FROM tableName
ORDER BY RPAD(dept_code, 10, '0')
- 10 could be the max length of your dept_code.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…