このクエリ結果を達成してパフォーマンスを向上させる簡単な方法はありますか?選択ごとに2つのテーブルを結合したくない。
select Product, LCTL, LQ, LCTQL from
(
(select 'Phone / HSI' as Product, (select count(1) as "LCTL" from tasks t,task_categories c where t.category_id=c.category_id and to_date(to_char(t.user_create_date,'DD-MON-YYYY'))>=?1 and to_date(to_char(t.user_create_date,'DD-MON-YYYY'))<=?2 and c.category_long_name='m ECOMM ORD') as LCTL,
(select count(1) as "LCTL" from tasks t,task_categories c where t.category_id=c.category_id and to_date(to_char(t.user_create_date,'DD-MON-YYYY'))>=?1 and to_date(to_char(t.user_create_date,'DD-MON-YYYY'))<=?2 and (c.category_long_name='CRIS ECOMM ORD' or c.category_long_name='CRIS ECOMM HELD')) as LQ,
(select count(1) as "LCTL" from tasks t,task_categories c where t.category_id=c.category_id and to_date(to_char(t.user_create_date,'DD-MON-YYYY'))>=?1 and to_date(to_char(t.user_create_date,'DD-MON-YYYY'))<=?2 and (c.category_long_name='CRIS ECOMM ORD' or c.category_long_name='CRIS ECOMM HELD' or c.category_long_name='m ECOMM ORD')) as LCTQL from dual
union all
select '(Phone / HSI) + Prism' as Product,(select count(1) as "LCTL" from tasks t,task_categories c where t.category_id=c.category_id and to_date(to_char(t.user_create_date,'DD-MON-YYYY'))>=?1 and to_date(to_char(t.user_create_date,'DD-MON-YYYY'))<=?2 and c.category_long_name='m ECOMM PRISM') as LCTL,
(select count(1) as "LCTL" from tasks t,task_categories c where t.category_id=c.category_id and to_date(to_char(t.user_create_date,'DD-MON-YYYY'))>=?1 and to_date(to_char(t.user_create_date,'DD-MON-YYYY'))<=?2 and c.category_long_name='CRIS ECOMM PRISM') as LQ,
(select count(1) as "LCTL" from tasks t,task_categories c where t.category_id=c.category_id and to_date(to_char(t.user_create_date,'DD-MON-YYYY'))>=?1 and to_date(to_char(t.user_create_date,'DD-MON-YYYY'))<=?2 and (c.category_long_name='m ECOMM PRISM' or c.category_long_name='CRIS ECOMM PRISM')) as LCTQL from dual
union all
select '(Phone / HSI) + DTV' as Product,(select count(1) as "LCTL" from tasks t,task_categories c where t.category_id=c.category_id and to_date(to_char(t.user_create_date,'DD-MON-YYYY'))>=?1 and to_date(to_char(t.user_create_date,'DD-MON-YYYY'))<=?2 and c.category_long_name='m ECOMM DTV') as LCTL,
(select count(1) as "LCTL" from tasks t,task_categories c where t.category_id=c.category_id and to_date(to_char(t.user_create_date,'DD-MON-YYYY'))>=?1 and to_date(to_char(t.user_create_date,'DD-MON-YYYY'))<=?2 and c.category_long_name='CRIS ECOMM DTV') as LQ,
(select count(1) as "LCTL" from tasks t,task_categories c where t.category_id=c.category_id and to_date(to_char(t.user_create_date,'DD-MON-YYYY'))>=?1 and to_date(to_char(t.user_create_date,'DD-MON-YYYY'))<=?2 and (c.category_long_name='m ECOMM DTV' or c.category_long_name='CRIS ECOMM DTV')) as LCTQL from dual
union all
select 'Total' as Product,(select count(1) as "LCTL" from tasks t,task_categories c where t.category_id=c.category_id and to_date(to_char(t.user_create_date,'DD-MON-YYYY'))>=?1 and to_date(to_char(t.user_create_date,'DD-MON-YYYY'))<=?2 and (c.category_long_name='m ECOMM DTV' or c.category_long_name='m ECOMM PRISM' or c.category_long_name='m ECOMM DTV')) as LCTL,
(select count(1) as "LCTL" from tasks t,task_categories c where t.category_id=c.category_id and to_date(to_char(t.user_create_date,'DD-MON-YYYY'))>=?1 and to_date(to_char(t.user_create_date,'DD-MON-YYYY'))<=?2 and (c.category_long_name='CRIS ECOMM DTV' or c.category_long_name='CRIS ECOMM PRISM' or c.category_long_name='CRIS ECOMM ORD' or c.category_long_name='CRIS ECOMM HELD')) as LQ,
(select count(1) as "LCTL" from tasks t,task_categories c where t.category_id=c.category_id and to_date(to_char(t.user_create_date,'DD-MON-YYYY'))>=?1 and to_date(to_char(t.user_create_date,'DD-MON-YYYY'))<=?2 and (c.category_long_name='m ECOMM DTV' or c.category_long_name='m ECOMM PRISM' or c.category_long_name='m ECOMM DTV' or c.category_long_name='CRIS ECOMM DTV' or c.category_long_name='CRIS ECOMM PRISM' or c.category_long_name='CRIS ECOMM ORD' or c.category_long_name='CRIS ECOMM HELD' )) as LCTQL from dual)
)
出力は次のようになります。
Product LCTL LQ LCTQL
Phone / HSI 17209 39849 57058
(Phone / HSI) + Prism 4095 6 4101
(Phone / HSI) + DTV 6192 1 6193
Total 10287 39856 50143