select c.f1,c.f2 from (select a.f1,a.f2+b.f2 as f2 from table1 a,table2 b) as c

解决方案 »

  1.   

    to hanlen
      你用的是什莫数据库?我在pb上试了一下(后台连Sybase),报错。好像SQL Server支持这样的用法。
      

  2.   

    select c.f1,c.f2 from (select a.f1,a.f2+b.f2 as f2 from table1 a,table2 b) as c 
    利用as 命令可以将select语句的中间结果当作一个表使用,不但可以使用一个中间结果还可以使用多个中间结果比如
    select c.f1,c.f2,d.f1,d.f2 from (select a.f1 as f1,a.f2+b.f2 as f2 from table1 a,table2 b) as c ,(select a.f1* b.f1 as f1 a.f2 * b.f2 as f2 from table1 a,table2 b) as d
      

  3.   

    这个结果在sql server里是没有问题的
      

  4.   

    你只要知道select 语句可以当作中间结果,在标准的sql语句中实现就没有问题
      

  5.   

    select aa.f1,aa.f2 
    from (select a.f1 f1,(a.f2+b.f2) f2 from table1 a,table2 b) aa,table3 
    where ...
      

  6.   

    同意wangyhao(亦豪),或许你找几本有关SQL的书看一下,有类似的例子(如:<数据库系统导论>等)
      

  7.   

    我希望使用Oracle或Sybase的朋友提出解决方法。谢谢以上各位的回答,但这样的语句在Oracle或Sybase之中是不能使用的。