表结构如下:
create table test(id varchar(20));
insert into test('testApp');
insert into test('testAPP');
insert into test('TestAPP');
insert into test('infosys');
insert into test('DataStar');
insert into test('Test');
问题描述:
今天在公司做项目时,遇到了这个问题。因工作关系,不用真实表,大家别拍砖啊.
这个表是以前的录入的数据.上面的这个数据不算是重复的,也不能更改,因为它有
很多引用关系.
现在需求:
新添加的数据要进行重复行判断
根据传入的查询条件id做重复判断,并且返回个数,id查询不区分大小写,
如id='testapp' 和 'testAPP'视为同一个字符串.
select count(*) from test t where t.id in(
lower('testApp'),
upper('testApp'),
'testApP')
--解决办法1
select count(*) from upm_app t
where
translate(id,lower('testApp')||upper('testApp')||id,lower('testApp')||lower('testApp'))
=lower('testApp');
有朋友说当test表数据量大的时候影响性能,大家一起分析下
--解决办法2
select count(*) from test t where lower(id) = lower('testapp')
create table test(id varchar(20));
insert into test('testApp');
insert into test('testAPP');
insert into test('TestAPP');
insert into test('infosys');
insert into test('DataStar');
insert into test('Test');
问题描述:
今天在公司做项目时,遇到了这个问题。因工作关系,不用真实表,大家别拍砖啊.
这个表是以前的录入的数据.上面的这个数据不算是重复的,也不能更改,因为它有
很多引用关系.
现在需求:
新添加的数据要进行重复行判断
根据传入的查询条件id做重复判断,并且返回个数,id查询不区分大小写,
如id='testapp' 和 'testAPP'视为同一个字符串.
select count(*) from test t where t.id in(
lower('testApp'),
upper('testApp'),
'testApP')
--解决办法1
select count(*) from upm_app t
where
translate(id,lower('testApp')||upper('testApp')||id,lower('testApp')||lower('testApp'))
=lower('testApp');
有朋友说当test表数据量大的时候影响性能,大家一起分析下
--解决办法2
select count(*) from test t where lower(id) = lower('testapp')