sql – 如何做一个区分大小写GROUP BY?
发布时间:2020-12-12 16:16:33 所属栏目:MsSql教程 来源:网络整理
导读:如果我执行下面的代码: 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 tempgroup by name 它返回结果: TEST 3tester 2 有没有
如果我执行下面的代码:
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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |