我有一个带有记录的列的SQL Server表:
Id Make
1 HONDA
2 Honda
3 TOYOTA
4 Toyota
5 toyota
6 BMW
7 BMW
我需要编写查询以仅显示具有不同字符大小写变体的字符串。数据库设置为不区分大小写。
结果类似于
honda
toyota
答案 0 :(得分:1)
您可以将EXISTS()
用作
SELECT Make
FROM T T1
WHERE EXISTS(
SELECT 1
FROM T
WHERE Make = UPPER(T1.Make)
AND
Make != T1.Make collate Latin1_General_CS_AS
);
甚至
SELECT LOWER(Make) Make
FROM T T1
WHERE EXISTS(
SELECT 1
FROM T
WHERE Make = UPPER(T1.Make)
AND
Make != T1.Make collate Latin1_General_CS_AS
)
GROUP BY LOWER(Make);
答案 1 :(得分:0)
您需要区分大小写的排序规则来进行比较。这是一个简单的方法:
select lower(str)
from (values ('honda'), ('Honda'), ('x'), ('x')) v(str)
group by lower(str)
having min(str collate Latin1_General_CS_AS) <> max(str collate Latin1_General_CS_AS);