有这个查询产生以下输出:
select sec.site,sec.Name,sec.Freq from
( select Name from sec group by name having count(Freq) > 3)as dt
inner join sec on dt.Name = sec.Name
where sec.Freq like '%MUF2900%' ;
site Name Freq
S003 sct003a MUF2900_26
S003 sct003a MUF2900_26
S003 sct003a MUF2900_26
S034 sct034a MUF2900_26
S034 sct034a MUF2900_26
S034 sct034a MUF2900_26
现在我必须根据上述查询的输出更新我的另一个表名测试。表测试当前包含以下记录(更新前):
site cell ID
S003 09M00011 1019581
S003 09M00012 1019582
S003 09M00013 1019583
S003 29M00011 1019581
S003 29M00012 1019582
S003 29M00013 1019583
S034 09M00011 1016581
S034 09M00011 1016582
S034 09M00011 1016583
now for site S003 , ID for for cell starting from 09 and 29 are same ,so i need to update the ID for 29 i.e the unit place of ID should be incremented by 10 , like following..
必需的 :
Site cell ID
S003 09M00011 1019581
S003 09M00012 1019582
S003 09M00013 1019583
S003 29M00011 10195811
S003 29M00012 10195812
S003 29M00013 10195813
S034 09M00011 1016581
S034 09M00011 1016582
S034 09M00011 1016583
我有很多这样的记录。
注意:S034 没有从 29 开始的单元格,所以它的 ID 不需要更新。
我尝试过的和我感到困惑的地方是:
update Test set ID = (how to do this ??)
where Test.site = (select sec.site,sec.Name,sec.Freq from
( select Name from sec group by Name having count(Freq) > 3)as dt
inner join sec on dt.Name = Sec.Name
where sec.Freq like '%MUF2900%') where cell like '29M%';
我应该怎么做。我需要为此制作光标吗??
从你的例子来看,下面的陈述应该做你想做的事。它并不快,因为它涉及将 ID 转换为字符串并对其进行操作,但我认为这是唯一适合您的方法。
如果 ID 是以字符串开头,那么您可以删除 CAST(ID AS VARCHAR(20)) 语句并将其替换为 ID。
好的,我自己解决了: