假设原始表结构(tableA):
客户名称 时间 费用select isnull(a.客户名称,b.客户名称) as 客户名称,isnull(本月用邮费用,0) as 本月用邮费用,isnull(上月用邮费用,0) as 上月用邮费用,(本月用邮费用-上月用邮费用)/上月用邮费用 as  增减百分比
from
(
select 客户名称,sum(费用) as 本月用邮费用
from tableA
where month(时间)=11
group by 客户名称
) as a full join 
(
select 客户名称,sum(费用) as 上月用邮费用
from tableA
where month(时间)=10
group by 客户名称
) as b
on a.客户名称=b.客户名称

解决方案 »

  1.   

    1、我用的是delphi,里面自带的数据库没有isnull函数
    我给你看看根据你写的sql语句,你看对吗customer_org.customer_name(客户名称),Saleslog.salestime(时间),Saleslog.income(用邮费用)select customer_org.customer_name as 客户名称, 本月用邮费用, 上月用邮费用,(本月用邮费用-上月用邮费用)/上月用邮费用 as  增减百分比
    from
    (
    select customer_org.customer_name,sum(Saleslog.income) as 本月用邮费用
    from customer_org, Saleslog
    where Saleslog.salestime>='2/1/2002' and Saleslog.customer_id=customer_org.customer_id
    group by customer_org.customer_name
    ) as a full join 
    (
    select customer_org.customer_name,sum(Saleslog.income) as 上月用邮费用
    from customer_org, Saleslog
    where Saleslog.salestime>='2/1/2002' and Saleslog.customer_id=customer_org.customer_id
    group by customer_org.customer_name
    ) as b
    on a.customer_name=b.customer_name
      

  2.   

    to strayatman(strayatman) 
    那你说说你那个数据库都可以用一些什么东东呀.case when这样的结构有吗?