现在的位置: 首页 > 综合 > 正文

当我们使用某个表达式作为输出的一列时,我们无法再Where条件中直接使用该列作判断条件

2013年10月05日 ⁄ 综合 ⁄ 共 755字 ⁄ 字号 评论关闭

http://topic.csdn.net/t/20050728/16/4174503.html#

 

  
  大家好!      
     
  我的问题是这样的:      
  当我们使用某个表达式作为输出的一列时,我们无法再Where条件中直接使用该列作判断条件.      
  例如下面的SQL语句:      
  select     id,     (c1     +     c2)     as     s      
  from     t1      
  where     s     >     100      
  SQL     Server     报错:     "列名     s     无效"      
     
  当然,写成      
  select     id,     (c1     +     c2)     as     s      
  from     t1      
  where     (c1     +     c2)     >     100      
  就没问题了.      
     
  可是当表达式复杂时就很繁琐了.      
     
  有没有可以在Where中使用这样的列名的办法?      
  或者有什么其他办法可以解决这类问题呢?      
     
  谢谢你们的指教!    
   
   
  ---------------------------------------------------------------      
     
  select     a.*     from      
  (select     id,     (c1     +     c2)     as     s      
  from     t1)     a      
  where     s     >     100      
     
  ---------------------------------------------------------------      
     
  select     a.*     from     (select     id,     c     =     c1+c2     from     t1)a      
            where     c     >     100      

抱歉!评论已关闭.