select  客户名称, a.本月用邮费用 , b.上月用邮费用,(a.本月用邮费用-b.上月用邮费用)/b.上月用邮费用 as  增减百分比 
from 
(
select customer_org.customer_name as 客户名称,sum(Saleslog.income) as 本月用邮费用
from customer_org, Saleslog
where Saleslog.salestime>='3/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 as 客户名称,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.客户名称=b.客户名称我在delphi 里的sql explore里执行,总是出错,说select 语句错误不知道为什么

解决方案 »

  1.   

    Saleslog.salestime>='2/1/2002' 把引号去掉试试。
    要是不行的话在把GROUP BY去掉试下。
      

  2.   

    select  客户名称, a.本月用邮费用 , b.上月用邮费用,(a.本月用邮费用-b.上月用邮费用)/b.上月用邮费用 as  增减百分比 
    from 
    ((
    select customer_org.customer_name as 客户名称,sum(Saleslog.income) as 本月用邮费用
    from customer_org, Saleslog
    where Saleslog.salestime>='3/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 as 客户名称,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.客户名称=b.客户名称)
      

  3.   

    select  a.客户名称, a.本月用邮费用 , b.上月用邮费用,(a.本月用邮费用-b.上月用邮费用)/b.上月用邮费用 as  增减百分比 
    from 
    (
    select customer_org.customer_name as 客户名称,sum(Saleslog.income) as 本月用邮费用
    from customer_org, Saleslog
    where Saleslog.salestime>='3/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 as 客户名称,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.客户名称=b.客户名称另外,日期最好用参数
      

  4.   

    honger:没错啊,到底是怎么回事????
    我是在delphi 自带的sql环境里(sql explore),执行的,不成功,提示
    Invalid use of keyword
    token:select
    line number:4
    zfmich() :你写的和我一开始写的有什么区别吗???
      

  5.   

    zfmich() 写的是正确的。区别是指名了客户名称的所属(a)
    另外,你的语句有一些bug
    b.上月用邮费用 不一定就不是0
    日期处理最好用convert指定格式,这样更好