怎么在select语句中实现计算顺序

如何在select语句中实现计算顺序

大概意思如下:

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

但这不是我想要的,不知道意思说清楚了吗。



–try

create table #A(c1 int,c2 int,c3 int)

insert into #A select 100,50,10

select * from #A

select (c3/2+10) as c1,(c3/2) as c2,c3

from #A

drop table #A



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




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语言。

怎么在select语句中实现计算顺序

相关文章:

你感兴趣的文章:

标签云: