Hi Guys,
I was wondering if i could get a helping hand in optimizing this query. I know its not perfectly formed and would really appreciate your expert guidance.
Select ISNull(a.pd_main_group_code_desc,b.pd_main_group_code_desc),
a.pd_super_group_desc ,a.Value_On_Promo,b.Value_On_Multi_Buy,
a.Profit_On_Promo,b.Profit_On_Multi_Buy from (
SELECT
pd_main_group_code,
pd_main_group_code_desc,
pd_super_group_desc,
sum(total_Price) AS Value_On_Promo,
sum(company_margin)AS Profit_On_Promo
FROM
Daily_Summary_Agg ds inner join Date_Dim dd on ds.date_id = dd.date_id
WHERE
po_code <> '0000'
AND pd_super_group_code NOT IN (95,93,99)
AND pd_main_group_code = (select pd_main_group_code from Product_Dim where pd_key = '665777' Group by pd_main_group_code)
AND dd.last_12_mths_flag = 'Y'
GROUP BY
pd_main_group_code_desc,
pd_main_group_code,
pd_super_group_desc)a
full outer Join (
SELECT
pd_main_group_code_desc,
pd_main_group_code,
sum(total_Price) Value_On_Multi_Buy,
sum(company_margin) Profit_On_Multi_Buy,
pd_super_group_desc
FROM
Daily_Summary_Agg ds inner join Date_Dim dd on ds.date_id = dd.date_id
WHERE
mb_deal_number <> '0000'
AND pd_super_group_code NOT IN (99,95,93)
AND pd_main_group_code = (select pd_main_group_code from Product_Dim where pd_key = '665777' Group by pd_main_group_code)
AND dd.last_12_mths_flag = 'Y'
GROUP BY
pd_main_group_code_desc,
pd_main_group_code,
pd_super_group_desc)b
On a.pd_main_group_code = b.pd_main_group_code