Привет, я пытался присоединиться к столу за другим столом присоединения. Я ожидаю, что весь код в CODE1, CODE2 и CODE3 будет показан так, как показано в таблице ниже:
channel_division_group staff_id the_code total update_dt
---------------------- -------- -------- ----- ---------
CH3 101 CODE1 1 03-Mar-11
CH3 101 CODE1 1 03-Mar-11
CH3 101 CODE2 1 03-Mar-11
CH3 101 CODE3 1 03-Mar-11
Но фактический результат - строка с CODE3 отсутствует:
channel_division_group staff_id the_code total update_dt
---------------------- -------- -------- ----- ---------
CH3 101 CODE1 1 03-Mar-11
CH3 101 CODE1 1 03-Mar-11
CH3 101 CODE2 1 03-Mar-11
Вот исходный код для вашей справки:
select channel_division_group, staff_id, the_code, total, update_dt
from (
select 'CODE1' the_code from dual
union all
select 'CODE2' the_code from dual
union all
select 'CODE3' the_code from dual
)
left outer join (
select a.staff_id, a.code, update_dt,
case when m.update_dt is null then 0
else count(*)
end total,
case a.channel_division_group
when 'CH1' then 'CH1'
when 'CH2' then 'CH2'
else 'CH3'
end tableC
from (
select code, staff.staff_id, staff.channel_division_group
from (
select 'CODE1' code, '1' seq from dual
union all
select 'CODE2' code, '2' seq from dual
union all
select 'CODE3' code, '3' seq from dual
), code_staff staff
) a
left outer join tableM m
on a.code = m.decision and to_char(a.staff_id)=m.approval_id
group by a.staff_id, a.code, update_dt, a.channel_division_group
order by a.channel_division_group, a.staff_id
) app
on the_code=app.code and staff_id=app.staff_id
where update_dt between trunc(to_date('13-MAR-11'), 'MONTH') and trunc(to_date('13-MAR-11'))
group by channel_division_group, staff_id, the_code, total, update_dt
order by staff_id;
Если я удаляю оператор предложения where, будет отображаться CODE3, но он не фильтруется в пределах даты. Можно ли это сделать, когда соединение за другим объединяется с предложением where?
Спасибо @!