                            sum(
                                if(
                                        pc1.channel_id is NULL, 
                                        if(
                                            pc.channel_id is NULL,
                                            pubrevenue_advcurrency,
                                            if(
                                                pc.model='CPM',
                                                impressions*(pc.price_per_unit*((c1.ex_rate)/(c2.ex_rate))),
                                                if(
                                                    ads.parent_ad_id IS NULL,
                                                    daily_stats.clicks,
                                                    0
                                                )
                                                *pc.price_per_unit*((c1.ex_rate)/(c2.ex_rate))
                                            )
                                        ),
                                        if(
                                            pc1.model='CPM',
                                            impressions*pc1.price_per_unit*((c1.ex_rate)/(c2.ex_rate)),
                                            if(
                                                ads.parent_ad_id IS NULL,
                                                daily_stats.clicks,
                                                0
                                            )
                                            *pc1.price_per_unit*((c1.ex_rate)/(c2.ex_rate))
                                        )
                                )
                                *1000
                                /sum(impressions)
                            )