大概意思如下:
A表
c1 c2 c3
100 50 10
如果select语句是如下形式
select (c2+10) as c1,
        (c3/2) as c2,
         c3
from A
想得到的结果是
c1 c2 c3
15 5 10
要求:先运算(c3/2),将结果作为c2后再执行(c2+10)作为c1,该如何实现上述的select语句?
注意:上述的select语句查询的结果是
c1 c2 c3
60 5 10
但这不是我想要的,不知道意思说清楚了吗。

解决方案 »

  1.   

    --trycreate table #A(c1 int,c2 int,c3 int)
    insert into #A select 100,50,10select * from #A
    select (c3/2+10) as c1,(c3/2) as c2,c3
    from #Adrop table #A
      

  2.   

    select 
            (c3/2+10) as c1,   --直接将C2替换为C3/2即可。
            (c3/2) as c2,
            c3
    from #A
      

  3.   

    真诚感谢wangtiecheng的帮助,让我再等等其他答案。
      

  4.   

    use wangtiecheng's test table #A
    变通处理
    select (select (c2+10) from (select (c3/2) as c2 from #A)t)as c1,(c3/2) as c2,c3 from #A
      

  5.   

    select c3/2+10 as c1,(c3/2) as c2,c3 from #A;不过,这个的道理其实就是把式子给展开了而已。
      

  6.   

    yhtapmys(极品猪) ( ) 信誉:100    Blog   加为好友  2007-05-16 13:42:25  得分: 0  
     
     
       use wangtiecheng's test table #A
    变通处理
    select (select (c2+10) from (select (c3/2) as c2 from #A)t)as c1,(c3/2) as c2,c3 from #A
      
    的道理其实是在sql级别的式子展开。
    总之,现在大家的实现方法依然是展开式子。
    而并没有从数据库上考虑。
    例如,C语言中
    int i=1;
    int a=i++,i+10,i--,i*8;
    最后输出i=18;a=17;
    这个就是楼主需要的吧。
    但是,数据库终归是数据库,而不是C语言。