求一条SQL语句!!!
顾客表Customer
id, name雇员表emp
id,name销售表Business
id
c_id(顾客表id)
e_id(雇员表id)
month (月份)
year(年)
amount销售数量 查出07年2月销售数量比1月多的顾员的id和name还有1月数量和2月数量并且还有增加的数量
顾客表Customer
id, name雇员表emp
id,name销售表Business
id
c_id(顾客表id)
e_id(雇员表id)
month (月份)
year(年)
amount销售数量 查出07年2月销售数量比1月多的顾员的id和name还有1月数量和2月数量并且还有增加的数量
select a.id,a.name,c.jan,c.feb,c.feb-c.jul faise_amt
from emp a,
(
select e_id,sum(decode(month,1,amount,0)) jan,sum(decode(month,2,amount,0)) feb
from Business b
where year='2007'
and month in (1,2)
group by e_id
) c
where a.id=c.e_id
and c.feb-c.jan>0
e.id,e.name,a.amount '1月',b.amount '2月',b.amount-a.amount '增加'
from
emp e,Business a,Business b
where
e.id=a.e_id
and
a.year=b.year and a.e_id=b.e_id
and
a.month='01' and b.month='02' and a.year='2007'
and
a.amount<b.amount