如何两个子查询师

时间:2012-11-09 07:48:06

标签: sql sql-server

我在以下子查询内部选择了两个。我想划分(subquery1 / subquery2)两个子查询。你是怎么做到的?

Select subquery1/subquery2,subquery1,subquery2 From.....

...谢谢

1 个答案:

答案 0 :(得分:2)

如果你有SQL Server 2005或更高版本,你可以这样做

select
    SQ.s1 / SQ.s2, SQ.s1, SQ.s2
from table as t
    outer apply (select subquery1 as s1, subquery2 as s2) as SQ

如果你有SQL 2000,那么你可以使用子查询:)

select
    SQ.s1 / SQ.s2, SQ.s1, SQ.s2
from
(
    select subquery1 as s1, subquery2 as s2
    from table as t
) as SQ