比如我有这样的查询, select col1,col2,col3 from table group by col1,col2,col3 这样没问题,
但是我有这样的查询 select col1, (select ... ...) as col2, (select .. ... )as col3 group by col1,col2,col3用别名分组不行,就说别名不可识别 ,求救

解决方案 »

  1.   

    select col1,col2,col3 from (select col1, (select ... ...) as col2, (select .. ... )as col3)  group by col1,col2,col3 
      

  2.   


    declare @t table(
    name varchar(10)
    )
    insert into @t select '1'
    insert into @t select '2'
    insert into @t select '3'
    insert into @t select '4'select * from @t
    select name from @t group by name
    --错误的用别名分组 
    --select name n from @t group by n
    --使用别名分组
    select *  from (select name n from @t) t group by n
      

  3.   

    第二种的col2,col3是你自己命名的,不属于table,所以无法识别。