所以这就是......按顺序为部门10,50,20制作一份工作清单。 使用set运算符显示作业ID和部门ID。 到目前为止我已经这样做了,但是我不能正确地进行排序(10,50,20),任何想法?...谢谢
SELECT job_id, department_id
FROM (SELECT job_id, department_id
FROM employees
WHERE department_id IN ('10','20','50')
INTERSECT
SELECT job_id, department_id
FROM employees
WHERE department_id IN ('10','20','50')
)
GROUP BY department_id, job_id
ORDER BY COUNT(job_id);
输出是这样的:
job_ID department_id
ST_CLERK 50
ST_MAN 50
MK_REP 20
SH_CLERK 50
AD_ASST 10
MK_MAN 20
答案 0 :(得分:1)
您可以使用CASE
语句来实现任意排序
ORDER BY (CASE department_id
WHEN 10 THEN 1
WHEN 50 THEN 2
WHEN 20 THEN 3
ELSE 4
END) ASC
答案 1 :(得分:1)
作为备注,您也可以instr()
:
order by instr(',10,50,20,', ',' || department_id || ',')
额外的逗号是为了确保类似子串(“110”和“10”)没有问题。对于这些特定值,这不是问题,因此您可以这样做:
order by instr('10,50,20', department_id)