我正在编写一个查询来为员工提取转出。这意味着排在行之前的行'转移'。有些员工在同一天有转移操作和另一个操作。但是我的查询获取的日期是<转移行动日期。我想写一些像这样的东西: -
select *
from per_all_assignments_m paam
where paam.effective_start_date=
(case if (paam.effective_start_date=
(select max(paam1.effective_start_date)
from per_all_assignments_m paam1
where paam1.person_id=paam.person_id and
paam.assignment_id=paam1.assignment_id and
paam1.action_code <> 'TRANSFER' and
paa1.effective_latest_change='N' )
)
then paam.effective_start_date
else (paam.effective_start_date=
(select max(paam1.effective_stat_date)
from per_all_assignments_m paam1
where paam.person_id=paam1.person_id and
paam.assignment_id=paam1.assignment_id and
paam1.effective_start_date <
(select max(paam2.effective_start_date)
from per_all_assignments_m paam2
where paam2.action_code='TRANSFER' and
paam1.person_id = paam2.person_id and
paam1.assignment_id=paam2.assignment_id)
)
)
)
是否可以在Oracle中使用?
答案 0 :(得分:1)
是的,有可能
SELECT
*
FROM
per_all_assignments_m paam
WHERE
paam.effective_start_date =
(
CASE
WHEN
paam.effective_start_date =
(
SELECT
MAX(paam1.effective_start_date)
FROM
per_all_assignments_m paam1
WHERE
paam1.person_id = paam.person_id AND
paam.assignment_id = paam1.assignment_id AND
paam1.action_code <> 'TRANSFER' AND
paa1.effective_latest_change = 'N'
)
THEN paam.effective_start_date
ELSE
(
SELECT
MAX(paam1.effective_stat_date)
FROM
per_all_assignments_m paam1
WHERE
paam.person_id = paam1.person_id AND
paam.assignment_id = paam1.assignment_id AND
paam1.effective_start_date <
(
SELECT
MAX(paam2.effective_start_date)
FROM
per_all_assignments_m paam2
WHERE
paam2.action_code = 'TRANSFER' AND
paam1.person_id = paam2.person_id AND
paam1.assignment_id = paam2.assignment_id
)
)
END -- closing END for case when..
)
答案 1 :(得分:0)
前一个应该有END)