All pastes #364799 Raw Edit

Something

public sql v1 · immutable
#364799 ·published 2007-02-20 12:14 UTC
rendered paste body
select t1.sales_reg,t1.pack_cod,(100-(((t1.total)-(t2.total))*100)/t1.total) as ret_per   from (    select sales_reg,pack_cod,sum(pre_ret+post_ret)as total      from projection      where no_of_mon =1      group by sales_reg,pack_cod      having sum(pre_ret+post_ret)>100  ) as t1,(    select sales_reg,pack_cod,sum(pre_ret+post_ret) as total      from projection      where no_of_mon =2      group by sales_reg,pack_cod      having sum(pre_ret+post_ret)>100  ) as t2  where t1.sales_reg=t2.sales_reg and t1.pack_cod=t2.pack_cod and t1.total>=t2.total  order by 3 desc  limit 5;