本帖最后由 guize 于 2014-12-26 14:45:39 编辑

解决方案 »

  1.   

    两个互斥条件,最后同一个字段输出。lz 最后 union all 输出的里面可能会有重复,如果不需要重复,直接用Union吧。 
      

  2.   

    select DISTINCT ISNULL([Frent_BrandId],[Frent_UserId]) AS Id
      from [Eble_ForRent]
    如果只返回一个字段的不重复值,也可以用 DISTINCT,不用 GROUP BY。
      

  3.   


    select (case when [Frent_BrandId] is not null then  [Frent_BrandId] 
      else [Frent_UserId] end) as resultCol
    from [Eble_ForRent]
      

  4.   


    select distinct case when [Frent_BrandId] is not null then [Frent_BrandId]
                         when [Frent_BrandId] is null then [Frent_UserId] end 'Frent_BrandId'
     from [Eble_ForRent] 
      

  5.   

    按你现有的业务要求,没办法简化了,不过你可以考虑两个查询语句都采用 distinct ,但不一定能提高效率。