SQL Server - 排序规则 - Latin1_General_CI_AS与Latin1_General_CS_AS之间的差异

时间:2021-02-14 10:20:09

How can I see the difference between

我怎么能看出它们之间的区别

SELECT * 
FROM (VALUES ('A'),('B'),('Y'),('Z'), ('a'),('b'),('y'),('z')) V(C)
ORDER BY C COLLATE Latin1_General_CS_AS

and

SELECT * 
FROM (VALUES ('A'),('B'),('Y'),('Z'), ('a'),('b'),('y'),('z')) V(C)
ORDER BY C COLLATE Latin1_General_CI_AS

?. For this set of characters there is no difference.

?。对于这组字符没有区别。

Cheers Bartosz

干杯巴托斯

1 个解决方案

#1


1  

Add an integer ID column to your set of values, and order by that after ordering by C.

将一个整数ID列添加到您的值集中,并按C排序后按顺序排序。

SELECT * 
FROM (VALUES  (1,'a'),(2,'b'),(3,'y'),(4,'z'),(5,'A'),(6,'B'),(7,'Y'),(8,'Z'),(9,'a'),(10,'b'),(11,'y'),(12,'z')) V(ID,C)
ORDER BY C COLLATE Latin1_General_CS_AS,ID

SELECT * 
FROM (VALUES (1,'a'),(2,'b'),(3,'y'),(4,'z'),(5,'A'),(6,'B'),(7,'Y'),(8,'Z'),(9,'a'),(10,'b'),(11,'y'),(12,'z')) V(ID,C)
ORDER BY C COLLATE Latin1_General_CI_AS,ID

For the first table, which is case sesitive, 'a' <> 'A', so they are treated seperately. Our ordering puts lowercase a first, and then orders them by ID (1, 9), and then follows with uppercase A.

对于第一个表格,这是一个案例敏感,'a'<>'A',所以它们是单独处理的。我们的排序首先将小写字母设为小写,然后按ID(1,9)对它们进行排序,然后按大写字母A进行排序。

ID  C
1   a
9   a
5   A

In the second table, 'a'='A', so they are treated in the same group, and the 3 a (or A) values are ordered together on ID number

在第二个表中,'a'='A',因此它们在同一组中处理,并且3个(或A)值在ID号上一起排序

ID  C
1   a
5   A
9   a

And this pattern continues for b, y and z.

并且这种模式对于b,y和z继续。

#1


1  

Add an integer ID column to your set of values, and order by that after ordering by C.

将一个整数ID列添加到您的值集中,并按C排序后按顺序排序。

SELECT * 
FROM (VALUES  (1,'a'),(2,'b'),(3,'y'),(4,'z'),(5,'A'),(6,'B'),(7,'Y'),(8,'Z'),(9,'a'),(10,'b'),(11,'y'),(12,'z')) V(ID,C)
ORDER BY C COLLATE Latin1_General_CS_AS,ID

SELECT * 
FROM (VALUES (1,'a'),(2,'b'),(3,'y'),(4,'z'),(5,'A'),(6,'B'),(7,'Y'),(8,'Z'),(9,'a'),(10,'b'),(11,'y'),(12,'z')) V(ID,C)
ORDER BY C COLLATE Latin1_General_CI_AS,ID

For the first table, which is case sesitive, 'a' <> 'A', so they are treated seperately. Our ordering puts lowercase a first, and then orders them by ID (1, 9), and then follows with uppercase A.

对于第一个表格,这是一个案例敏感,'a'<>'A',所以它们是单独处理的。我们的排序首先将小写字母设为小写,然后按ID(1,9)对它们进行排序,然后按大写字母A进行排序。

ID  C
1   a
9   a
5   A

In the second table, 'a'='A', so they are treated in the same group, and the 3 a (or A) values are ordered together on ID number

在第二个表中,'a'='A',因此它们在同一组中处理,并且3个(或A)值在ID号上一起排序

ID  C
1   a
5   A
9   a

And this pattern continues for b, y and z.

并且这种模式对于b,y和z继续。