在select子句中进行子选择并使用其值

时间:2017-11-02 11:06:12

标签: sql sql-server

有一种方法可以返回依赖于该字段的子选择和返回操作吗?

例如,我可以这样做:

select a, (select top 1 b from b) as b, (a * b) as c
from a

2 个答案:

答案 0 :(得分:2)

select a, b, (a * b) as c
from (
    select a, (select top 1 b from b) as b
    from a
) x

答案 1 :(得分:0)

将子查询放在from子句中:

select a.a, b.b, (a.a * b.b) as c
from a cross join
     (select top 1 b from b) b;