有表User
字段:UserID,LoginName,PassWord
其中LoginName有如下示例数据:haha50005
haha50006
の删除记忆…
の删除记忆”现在需要有这样的SQL语句,能够将名字里面包含了两个以上相同文字和连续3个以上相同数字和字母的排除,只留一个结果如:Userid LoginName Password1 haha50005 123
3 の删除记忆… 123
字段:UserID,LoginName,PassWord
其中LoginName有如下示例数据:haha50005
haha50006
の删除记忆…
の删除记忆”现在需要有这样的SQL语句,能够将名字里面包含了两个以上相同文字和连续3个以上相同数字和字母的排除,只留一个结果如:Userid LoginName Password1 haha50005 123
3 の删除记忆… 123
insert @t select 'haha50005','123'
insert @t select 'haha50006' ,465679
insert @t select 'の删除记忆…' ,456
insert @t select 'の删除记忆”',123456
select * from @t t where not exists(select 1 from @t where left(loginname,3)=left(t.loginname,3) and t.id>id)
這樣可以嗎?
"from Mtemp , Moff " & _
"where Mtemp.office_ID=Moff.office_ID and Mtemp.signal_name='门禁' " & _
"order by office_name,signal_name, xuhao"
这是一个写入的语句,供你参考
insert @t select 'haha50005','123'
insert @t select 'haha50006' ,465679
insert @t select 'の删除记忆…' ,456
insert @t select 'の删除记忆”',123456
select * from @t t where not exists(select 1 from @t where left(loginname,3)=left(t.loginname,3) and t.id>id)
這樣可以嗎?
-----------------------如果加这样一条数据就不能达到要求了。不过也已经很好了,谢谢
insert @t select 'h1ah1a50006' ,465679 你的这个语句只能筛选前面相同的
select * from [user] where id in (select min(id) from [user] group by left(LoginName,3))
试一下这个
2 删除中国
3 中国asdf问下这种情况是什么显示显示
1 删除记忆
2 删除中国??
create function f_compstr(
@str1 varchar(8000),
@str2 varchar(8000)
) returns bit
as
begin
declare @re bit,@lstr varchar(8000),@sstr varchar(8000)
declare @tb table(id int identity(1,1),a int)
insert into @tb(a) select top 100 null from sysobjects a,sysobjects b if len(@str1)>len(@str2)
select @lstr=@str1,@sstr=@str2
else select @lstr=@str2,@sstr=@str1 set @re=case when exists(
select 1
from (select name=@sstr)a,@tb b
where (b.id<=len(@sstr)-2 and @lstr like '%'+substring(name,b.id,3)+'%')
or (b.id<=len(@sstr)-1 and @lstr like '%'+substring(name,b.id,2)+'%' and patindex('%[^吖-座]%',substring(name,b.id,2))=0)
) then 1 else 0 end return(@re)
end--测试数据
declare @t table(ID int identity(1,1),loginname varchar(20),password varchar(10))
insert @t select 'haha50005','123'
union all select 'haha50006' ,'465679'
union all select '50006haha' ,'469'
union all select 'の删除记忆…','456'
union all select '美好的记忆”','123456' select * from @t a where id =(select min(id) from @t where dbo.f_compstr(a.loginname,loginname)=1) --结果
/*
ID loginname password
----------- -------------------- ----------
1 haha50005 123
4 の删除记忆… 456(所影响的行数为 2 行)
*/