How to do a case sensitive GROUP BY?

前端 未结 4 1245
南旧
南旧 2020-12-03 02:46

If I execute the code below:

with temp as
(
  select \'Test\' as name
  UNION ALL
  select \'TEST\'
  UNION ALL
  select \'test\'
  UNION ALL
  select \'test         


        
4条回答
  •  囚心锁ツ
    2020-12-03 03:35

    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
    

提交回复
热议问题