如果我执行下面的代码:
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
它返回结果:
TEST 3 tester 2
有没有办法让小组区分大小写,结果将是:
Test 1 TEST 1 test 1 tester 2
解决方法
您可以使用区分大小写的排序规则:
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