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.客户名称分别执行 a ,b都没有错,为什么合在一起就不行?是不是full join 有问题,也不象是有问题啊?
我是在delphi的sql explore 里执行的
错误提示:提示
Invalid use of keyword
token:select
line number:4

解决方案 »

  1.   

    select  a.客户名称, a.本月用邮费用 , b.上月用邮费用,(a.本月用邮费用-b.上月用邮费用)/b.上月用邮费用 as  增减百分比 
    from 
    后面的内容用括号括起来不行嘛?
      

  2.   

    你把基本的两个表的结构sql贴出来。
    一定帮你解决。
    本版当然能够解决啦,只不过带星星的大牛没出现罢了。
      

  3.   

    同意 flyingkiller(大飞虫) 
        把表结构脚本贴出来。
      

  4.   

    你试一下left join 啊。
      

  5.   

    你分别执行a,和b的时候出来的结果是你想要的嘛?
    Saleslog.salestime>='2/1/2002' 这样写是不是有问题
      

  6.   

    这种Sql语句你也能写的出来?第一个From 之后的语句是生成一个临时表的,
    第一个Select语句的a.*  b.*都不对。
      

  7.   

    还是那句请注明数据库
    如果是本地表 .db dbf之流不支持as a ,as b那两句很正常
      

  8.   

    这是个sql问题,和delphi的能力无关
      

  9.   

    好的 ,表结构如下
    客户用邮记录 Saleslog
    Log_ID 序号 char 10
    customer_id 客户编号 char 15
    customer_type 客户类型 Number 1
    sales_time 用邮时间 Date
    bsn_id 业务种类 char 6
    unit_price 单价 Number 8.2
    sales_count 业务量 Number 9.3
    income 用邮费用 Number 9.3单位大客户 customer_org
    customer_id 客户编号 Char 15
    customer_name 客户名称 vc 80
    admin_code 所在区域代码 Char 6
    address 通信地址 vc 60
      

  10.   

    diruser(我来也):
    我这个sql怎么错了??你改成字母试试还是同样的错误,我本来from 后面用的就是临时表啊?
      

  11.   

    Saleslog.salestime>='2/1/2002' 你这个sql语句不对,在explore里不能执行这样的时间条件,你还是用Query中设置SQL来达到你的目的吧。
      

  12.   

    我就是在sql explore里(summry/enter sql)执行的,装delphi时自带的sql执行环境,上面就是sql语句,那里还用什么脚本啊???
      

  13.   

    还是那句请注明数据库
    脚本的意思是
    create table Saleslog
    (...
    )
      

  14.   

    我用SQL SERVER帮你试过了,除了sales_time写错了(估计是哪笔误了),其他没有问题啊。所以还是要注明数据库
      

  15.   

    在空白库里执行是没有问题的
      有问题的应该是联合的问题,还有我测试下面语句在一条记录的时候没有错
    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>=2002-03-01 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>=2002-02-01 and Saleslog.customer_id=customer_org.customer_id
    group by customer_org.customer_name
    ) as b
    on a.客户名称=b.客户名称
      

  16.   

    是不是我的数据库不支持这些关键字啊,我用的是delphi 自带的standard数据库