select a , (很复杂子查询) as temp_b , c*(很复杂子查询)  as temp_c from table1

解决方案 »

  1.   

    或者
    select (很复杂子查询) into #tmp
    #tmp再跟 table1关联写select
      

  2.   

    应该不会影响速度吧:
    select a , (很复杂子查询) as temp_b , c*(很复杂子查询)  as temp_c from table1
    你再试试这样写效率怎么样?
    select a,temp_b,c*temp_b as temp_c from (select *,很复杂子查询) as temp_b from table1) t
      

  3.   

    那句“复杂的子查询”让很多人迷糊,所以问题可不可以转化成CREATE TABLE [dbo].[TestTable] (
    [id] [int] IDENTITY (1, 1) NOT NULL ,
    ) ON [PRIMARY]insert into t1 default values
    insert into t1 default values
    insert into t1 default values--然后执行
    select id,id*2 as col1,col1*3 as col2 from t1
    --服务器: 消息 207,级别 16,状态 3,行 1
    --Invalid column name 'tt'.
    --出错了问题叙述到此为止,大家有没有解决的高见?
    我只想到了最通俗的解法
    select id,id*2 as col1,id*2*3 as col2 from t1
      

  4.   

    --更正,表名写错了
    --那句“复杂的子查询”让很多人迷糊,所以问题可不可以转化成CREATE TABLE [dbo].[TestTable] (
    [id] [int] IDENTITY (1, 1) NOT NULL ,
    ) ON [PRIMARY]insert into TestTable default values
    insert into TestTable default values
    insert into TestTable default values--然后执行
    select id,id*2 as col1,col1*3 as col2 from TestTable
    --服务器: 消息 207,级别 16,状态 3,行 1
    --Invalid column name 'col1'.
    --出错了--问题叙述到此为止,大家有没有解决的高见?
    --我只想到了最通俗的解法
    select id,id*2 as col1,id*2*3 as col2 from TestTable
      

  5.   

    再写一遍很复杂的子查询也没什么,不会影响速度,查询分析引擎会自动优化。
    只是sql语句写得太长,不好看而已。
    x_zing(阿浩)的建议也不错,只是在“很复杂子查询”前少了个括号。