关于同一字段的加减处理的思路



昨天做到两个表的同一字段的处理就歇菜了,网上的资料也是说自身join自身,然后通过id来定位来进行相邻字段的相减。
第二个方法是通过case when来判断是什么类别的字段然后将其它表中的东西放入到这个字段中来。然后进行统一的处理。

1
2
3
4
case when Mailing_Group_Dev_Cnt <>0 then 1.000*Click_Cnt/Mailing_Group_Dev_Cnt else null end as CTR
,sum(case when CAMP_PRO.Lead_Type_Id = '60' then CAMP_PRO.Targeted_User_Cnt else 0 end) as Control_Group_Target_Cnt
,sum(case when CAMP_PRO.Lead_Type_Id = '999' then CAMP_REV.Email_Campaign_Cnvrsn_Cnt else 0 end) as Mailing_Group_Conv
,sum(case when CAMP_PRO.Lead_Type_Id = '60' then CAMP_REV.Email_Campaign_Cnvrsn_Cnt else 0 end) as Control_Group_Conv