本文介绍了如何做区分大小写的GROUP BY?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我执行下面的代码:
If I execute the code below:
with temp as
(
select 'Test' as name
UNION ALL
select 'TEST'
UNION ALL
select 'test'
UNION ALL
select 'tester'
UNION ALL
select 'tester'
)
SELECT name, COUNT(name)
FROM temp
group by name
它会返回结果:
It returns the results:
TEST 3
tester 2
有没有办法让群组区分大小写,以便结果是:
Is there a way to have the group by be case sensitive so that the results would be:
Test 1
TEST 1
test 1
tester 2
推荐答案
您可以使用区分大小写的排序规则:
You can use an case sensitive collation:
with temp as
(
select 'Test' COLLATE Latin1_General_CS_AS as name
UNION ALL
select 'TEST'
UNION ALL
select 'test'
UNION ALL
select 'tester'
UNION ALL
select 'tester'
)
SELECT name, COUNT(name)
FROM temp
group by name
这篇关于如何做区分大小写的GROUP BY?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!