表AID 字段A 字段B
1 赣B88888 北京,江西南昌,深圳,上海
2 粤 北京,江西赣州,江苏南京
3 蒙C 全国,广东,内蒙古
4 赣B88888 北京,江西九江,四川语句分开来写
要求
1.删除字段A字数小于3个字的
2.删除字段B中的江西其他的保留
3.当字段A中有重复的删除ID最大的是分开来写哦
谢谢大家
1 赣B88888 北京,江西南昌,深圳,上海
2 粤 北京,江西赣州,江苏南京
3 蒙C 全国,广东,内蒙古
4 赣B88888 北京,江西九江,四川语句分开来写
要求
1.删除字段A字数小于3个字的
2.删除字段B中的江西其他的保留
3.当字段A中有重复的删除ID最大的是分开来写哦
谢谢大家
update 表A set 字段B=replace(字段B,'江西','')
where charindex('江西',字段B )>0
[/code]
from @Resource a
where
not exists(select 1 from @Resource where id=a.id and name=a.name and id> a.id)
from @Resource a
where
not exists(select 1 from @Resource where id=a.id and id> a.id)
1.删除字段A字数小于3个字的
delete from a where Len(字段A)<3
2.删除字段B中的江西其他的保留
delete from a where CharIndex('江西',字段B)<>0
3、delete a where ID in (
select MAX(ID) from a group by a having COUNT(*)>1)2、UPDATE a SET 字段b=Replace(字段B,'江西','') where charindex('江西','字段B')<>01、 delete a where datalength(a)<3
--3.当字段A中有重复的删除ID最大的
delect 表A as a where exists(select 1 from 表A where 字段A=a.字段A and ID<a.ID)
http://topic.csdn.net/u/20080626/00/43d0d10c-28f1-418d-a05b-663880da278a.html
delete from 表 where len(字段A)<3
--2.
delete from 表 where charindex('江西',字段B)>0
--3.
delete a from 表 a where id not in(select min(id) from 表 where 字段A=a.字段A)
DELETE FROM ta WHERE LEN(f1)<3
2
有一种情况
北京,江西,上海直接replace会出现 北京,,上海 这样有问题。如果是指删除
DELETE FROM ta WHERE fb LIKE '%江西%'
如果是指update
那么写起来还要复杂一点,看楼主是说哪种情况了,再写
3
DELETE a FROM ta a
INNER JOIN
(SELECT MAX(id) mi,fa FROM tb GROUP BY fa) b
ON b.fa=a.fa AND id!=mi
有同感。删除了id最大的,那还是可能有重复。
应该是留下id最大的,或id最小的。这样就去重了。
1 赣B88888 北京,江西南昌,深圳,上海 1 13188888888
2 粤 北京,江西赣州,江苏南京 0 13900000000
3 蒙C 全国,广东,内蒙古 1 15977777777
4 赣B88888 北京,江西九江,四川 0 13688888888语句分开来写
要求
1.删除字段A字数小于3个字的
2.删除字段B中的江西其他的保留
3.当字段A中有重复的删除ID最大的 是分开来写哦
谢谢大家新问题
删除MOB字段131开头的
--删除MOB字段131开头的
delete 表A where left(字段MOB ,3)='131'
--排序这样?
declare @tb table(ID int, 字段A nvarchar(50), 字段B nvarchar(100))
insert @tb
select 1 , N'赣B88888' , N'北京,江西南昌,深圳,上海' union all
select 2 , N'粤' , N'北京,江西赣州,江苏南京' union all
select 3 , N'蒙C' , N'全国,广东,内蒙古' union all
select 4 , N'赣B88888' , N'北京,江西九江,四川'select * from @tb
order by replace(字段A,N'赣',' '),ID DESC
/*
ID 字段A 字段B
----------- -------------------------------------------------- ----------------------------------------------------------------------------------------------------
4 赣B88888 北京,江西九江,四川
1 赣B88888 北京,江西南昌,深圳,上海
3 蒙C 全国,广东,内蒙古
2 粤 北京,江西赣州,江苏南京(4 row(s) affected)
*/
delete from 表 where len(字段A)<3
--2.
update 表 set 字段B=replace(字段B,'江西','')
--3.
delete t from 表 t where exists (select 1 from 表 where 字段A=t.字段A and ID<t.ID)
--4.
delete 表 where MOB字段 like '131%'
if object_id('表A')is not null
drop table 表A
go
create table 表A
( id int,
字段A nvarchar(10),
字段B nvarchar(20)
)
insert into 表A select 1,'赣B88888','北京,江西南昌,深圳,上海'
UNION ALL
select 2,'粤','北京,江西赣州,江苏南京'
UNION ALL
select 3,'蒙C','全国,广东,内蒙古'
UNION ALL
select 4,'赣B88888','北京,江西九江,四川'
select * from 表A
1.delete 表A where len(字段A)<3
2.update 表A set 字段B= replace(字段B,'江西','')
where charindex('江西',字段B)>0
3. delete a from 表A a join (select min(id) id, 字段A from 表A GROUP BY 字段A )b
on a.id!=b.id and a.字段A=b.字段A