powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Oracle [игнор отключен] [закрыт для гостей] / LEFT JOIN/UNION
3 сообщений из 3, страница 1 из 1
LEFT JOIN/UNION
    #39745144
1dva3
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Добрый день!
У меня проблема с объединением двух запросов. Первый запрос считает открытые/закрытые установки по услугам связи А, второй запрос считает открытые/закрытые установки по услугам связи Б.
Мне необходимо вывести результат одним запросом. В Результате должно быть 5 столбцов.
Регион Открытые СТС, Закрытые СТС, Открытые ГТС, Закрытые ГТС
пример.

--Атырау СТС

select trim(r.name) "РЕГИОН",
sum(case when od.end_sysdate is not null then 1 end)"Закрытые СТС" , --ЭТО УСЛУГА А
sum(case when od.end_sysdate is null then 1 end) "Открытые СТС"
from db.order_device od, db.report_date rd, db.device_group dg, db.connect_type ct, db.town t,
db.region r, db.crm_server cs,
(select 383074 id from dual union
select 144786 from dual) tab
where tab.id=od.abonent_id
and od.new_connect_type_id=ct.id
and od.begin_sysdate between rd.from_date and rd.to_date
and rd.id=11
and dg.id=od.device_group_id
and dg.id= decode(cs.id, 3, 24, 13, 33, 4, 37, 11, 24, -1)
and od.town_id=t.id
and t.region_id=r.id
and od.action_id in (9)
group by r.name

------------------------
--Атырау ГТС
union all
select trim(r.name) "РЕГИОН",
sum(case when od.end_sysdate is not null then 1 end)Закрытые ГТС, --ЭТО Услуга Б
sum(case when od.end_sysdate is null then 1 end) "Открытые ГТС"
from db.order_device od, db.report_date rd, db.device_group dg, db.connect_type ct, db.town t,
db.region r, db.crm_server cs,
(select 131690 id from dual union
select 343792 from dual) tab
where tab.id=od.abonent_id
and od.new_connect_type_id=ct.id
and od.begin_sysdate between rd.from_date and rd.to_date
and rd.id=11
and dg.id=od.device_group_id
and dg.id= decode(cs.id, 3, 24, 13, 33, 4, 37, 11, 24, -1)
and od.town_id=t.id
and t.region_id=r.id
and od.action_id in (9)
group by r.name
order by 1
...
Рейтинг: 0 / 0
LEFT JOIN/UNION
    #39745152
Dshedoo
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Код: plsql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
select trim(r.name) "РЕГИОН",
sum(case when tab.ulsuga = 'A' and od.end_sysdate is not null then 1 end)"Закрытые СТС" , --ЭТО УСЛУГА А
sum(case when tab.ulsuga = 'A' and od.end_sysdate is null then 1 end) "Открытые СТС"
sum(case when tab.ulsuga = 'Б' and od.end_sysdate is not null then 1 end)Закрытые ГТС, --ЭТО Услуга Б
sum(case when tab.ulsuga = 'Б' and od.end_sysdate is null then 1 end) "Открытые ГТС"
from db.order_device od, db.report_date rd, db.device_group dg, db.connect_type ct, db.town t,
db.region r, db.crm_server cs,
(select 383074 id, 'A' as usluga from dual union
select 144786, 'A' from dual union
select 131690, 'Б' from dual union
select 343792, 'Б' from dual) tab
where tab.id=od.abonent_id
and od.new_connect_type_id=ct.id
and od.begin_sysdate between rd.from_date and rd.to_date
and rd.id=11
and dg.id=od.device_group_id
and dg.id= decode(cs.id, 3, 24, 13, 33, 4, 37, 11, 24, -1)
and od.town_id=t.id
and t.region_id=r.id
and od.action_id in (9)
group by r.name
...
Рейтинг: 0 / 0
LEFT JOIN/UNION
    #39745153
Фотография Elic
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
1dva3В Результате должно быть 5 столбцов.
Регион Открытые СТС, Закрытые СТС, Открытые ГТС, Закрытые ГТСfull join
...
Рейтинг: 0 / 0
3 сообщений из 3, страница 1 из 1
Форумы / Oracle [игнор отключен] [закрыт для гостей] / LEFT JOIN/UNION
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]