如何写这个SQL语句更新在哪里?

时间:2012-08-08 12:50:13

标签: sql excel tsql sql-server-2008-r2

Update [E1$] 
set [LR/Virtual/MW]='LR' ,  
[Vir No#]=null  
where [Conc] , [Vir No#]
  in   (    
    SELECT  [Conc] , [Vir No#]
    FROM [E1$]  
    where [Vir No#] is not null 
    group by Conc , [Vir No#] 
    having  Count(LR)<28
) 

3 个答案:

答案 0 :(得分:2)

试试这个:

    Update E set [LR/Virtual/MW]='LR' , [Vir No#]=null  
  from [E1$] E join
       (SELECT  [Conc] , [Vir No#]
        FROM [E1$] where [Vir No#] is not null 
        group by Conc ,[Vir No#] 
        having  Count(LR)<28
       ) a
 on e.[Conc]=a.[Conc] 
    and e.[Vir No#]=a.[Vir No#]

答案 1 :(得分:0)

尝试在([conc], [Vir No#])子句中使用where左右的括号。

Update [E1$] 
set [LR/Virtual/MW]='LR' ,  
[Vir No#]=null  
where ([Conc] , [Vir No#]) in
(    
   SELECT  [Conc] , [Vir No#]
   FROM [E1$]  
   where [Vir No#] is not null 
   group by Conc , [Vir No#] 
   having  Count(LR)<28
) 

答案 2 :(得分:0)

Update [E1$] 
set [LR/Virtual/MW]='LR',[Vir No#]=null  
where exists(    
    SELECT  [Conc] , [Vir No#]
    FROM [E1$] e2 
    where [Vir No#] is not null and  [E1$].[Conc]=e2.[Conc] and [E1$].[Vir No#]=e2.[Vir No#]
    group by Conc , [Vir No#] 
    having  Count(LR)<28
)