把3条sql合为1条。 sql1/sql2 为同期比sql1="select sum(num) from 销售数据表 where region||unit='北京百盛' and h_date=to_date('2009-05-20','yyyy-mm-dd')"sql2="select sum(num) from 销售数据表 where region||unit='北京百盛' and h_date=to_date('2009-05-20','yyyy-mm-dd')-365" sql="select b.head as 负责人,a.region as 地区,a.unit as 单店,a.dd_level||a.areas as 类别 from 单店基础信息表new a,单店营运职责表 b where 1=1"这合并的语句好像有问题,哪位高手指点下select b.head as 负责人,a.region as 地区,a.unit as 单店,a.dd_level||a.areas as 类别 ,(1-(round((select sum(num) from 销售数据表 where region||unit='北京百盛' and h_date=to_date('2009-05-22','yyyy-mm-dd'))/(select sum(num) from 销售数据表 where region||unit='北京百盛' and h_date=to_date('2009-05-22','yyyy-mm-dd')-365),0))) as销量同期比 from 单店基础信息表new a,单店营运职责表 b,销售数据表 c
你执行的时候报什么错误呢?我看到一处语法错误:select b.head as 负责人,a.region as 地区,a.unit as 单店,a.dd_level||a.areas as 类别 ,(1-(round((select sum(num) from 销售数据表 where region||unit='北京百盛' and h_date=to_date('2009-05-22','yyyy-mm-dd'))/(select sum(num) from 销售数据表 where region||unit='北京百盛' and h_date=to_date('2009-05-22','yyyy-mm-dd')-365),0))) as 销量同期比 from 单店基础信息表new a,单店营运职责表 b,销售数据表 cas销量同期比 你写到一起去了,应该改为 as 销量同期比
select max(b.head) as 负责人,a.region as 地区,a.unit as 单店,max(a.dd_level||a.areas) as 类别 ,
1-round(sum(c.num)/sum(d.num),0) as 销量同期比
from 单店基础信息表new a,单店营运职责表 b,销售数据表 c,销售数据表 d
where a.region=b.region and a.商场=b.商场
and a.region=c.region and a.商场=c.商场
and a.region=d.region and a.商场=d.商场
and c.h_date=d.h_date+365
and c.date=to_date('2009-05-20','yyyy-mm-dd')
and c.region||c.unit='北京百盛'
group by a.region,a.unit;
改成
and c.h_date=to_date('2009-05-20','yyyy-mm-dd')
改成
1-round(sum(c.num)/sum(d.num),2) as 销量同期比
再试