select cd.cust_code,sp.currency,
case when cd.eta>=to_date('2011-01-01','yyyy-mm-dd') and cd.eta<to_date('2011-02-01','yyyy-mm-dd') then sum(cd.cfc_qty*sp.price) as Jan_Amount
when cd.eta>=to_date('2011-02-01','yyyy-mm-dd') and cd.eta<to_date('2011-03-01','yyyy-mm-dd') then sum(cd.cfc_qty*sp.price) as Feb_Amount
when cd.eta>=to_date('2011-03-01','yyyy-mm-dd') and cd.eta<to_date('2011-04-01','yyyy-mm-dd') then sum(cd.cfc_qty*sp.price) as Mar_Amount
else 0
end as cd.cfc_qty*sp.price
from cfc_detail cd,selling_price sp
where sp.cust_code =cd.cust_code
group by cd.cust_code,
sp.currency
order by cd.cust_code
我要按客户查询 一月 ,二月和三月的销售额 以上sQl有错,求正解!
输出格式为
cust_code currency Jan_Amount Feb_Amount Mar_Amount
case when cd.eta>=to_date('2011-01-01','yyyy-mm-dd') and cd.eta<to_date('2011-02-01','yyyy-mm-dd') then sum(cd.cfc_qty*sp.price) as Jan_Amount
when cd.eta>=to_date('2011-02-01','yyyy-mm-dd') and cd.eta<to_date('2011-03-01','yyyy-mm-dd') then sum(cd.cfc_qty*sp.price) as Feb_Amount
when cd.eta>=to_date('2011-03-01','yyyy-mm-dd') and cd.eta<to_date('2011-04-01','yyyy-mm-dd') then sum(cd.cfc_qty*sp.price) as Mar_Amount
else 0
end as cd.cfc_qty*sp.price
from cfc_detail cd,selling_price sp
where sp.cust_code =cd.cust_code
group by cd.cust_code,
sp.currency
order by cd.cust_code
我要按客户查询 一月 ,二月和三月的销售额 以上sQl有错,求正解!
输出格式为
cust_code currency Jan_Amount Feb_Amount Mar_Amount
解决方案 »
- 急急急,银联接口问题!
- 学JAVA EE 一定要用MyEclipse吗??
- 求extjs分页代码,后台数据用Java的action传递
- JFreeChart 输出流问题!
- 如何把文本写入数据库的过滤掉一些HTML符号?
- EJB不能使用java.io包
- 求救各位大哥大姐Struts中文能试的已经都试过了
- 求comm.jar
- struts 1.1的struts-tiles.tld和struts-template.tld有何区别?好象是实现类似功能啊?
- 求救关于一个对空数据库操作的问题.
- java调试的问题,怎样找这行代码上面的内容?
- java求解链接地址在http://topic.csdn.net/u/20101229/11/7c94d0d8-4618-4e5e-9fee-328acf930
a.currency,
sum(a.Jan_Amount) as Jan_Amount,
sum(a.Feb_Amount) as Feb_Amount,
sum(a.Mar_Amount) as Mar_Amount
from (select a.cust_code,
b.currency,
a.eta,
decode(trunc(a.eta, 'mm'),
to_date('2011-01-01', 'yyyy-mm-dd'),
sum(a.cfc_qty * b.price)) as Jan_Amount,
decode(trunc(a.eta, 'mm'),
to_date('2011-02-01', 'yyyy-mm-dd'),
sum(a.cfc_qty * b.price)) as Feb_Amount,
decode(trunc(a.eta, 'mm'),
to_date('2011-03-01', 'yyyy-mm-dd'),
sum(a.cfc_qty * b.price)) as Mar_Amount
from cfc_detail a, selling_price b
where a.cust_code = b.cust_code
group by a.cust_code, b.currency, a.eta
order by a.cust_code) a
group by a.cust_code, a.currency;