“MySQL 字符集:排序规则问题”的版本间差异
跳到导航
跳到搜索
(建立内容为“category:MySQL == 在 SQL 语句中使用“COLLATE” == == “COLLATE”子句优先级 == == 字符集和排序规则兼容性 == == 表达式中的排…”的新页面) |
|||
第2行: | 第2行: | ||
== 在 SQL 语句中使用“COLLATE” == | == 在 SQL 语句中使用“COLLATE” == | ||
使用“COLLATE”子句,您可以覆盖默认的默认排序规则以进行比较。'''“COLLATE”可用于 SQL 语句的各个部分。'''这里有些例子: | |||
# 使用“ORDER BY”:【对中文排序呢???拼音升降序使用什么排序规则???】 | |||
#: '''<syntaxhighlight lang="xml"> | |||
SELECT k | |||
FROM t1 | |||
ORDER BY k COLLATE latin1_german2_ci;''' | |||
</syntaxhighlight> | |||
# 使用“AS”: | |||
#: '''<syntaxhighlight lang="xml"> | |||
SELECT k COLLATE latin1_german2_ci AS k1 | |||
FROM t1 | |||
ORDER BY k1; | |||
</syntaxhighlight>''' | |||
# 使用“GROUP BY”: | |||
#: '''<syntaxhighlight lang="xml"> | |||
SELECT k | |||
FROM t1 | |||
GROUP BY k COLLATE latin1_german2_ci; | |||
</syntaxhighlight>''' | |||
# 具有聚合功能: | |||
#: <syntaxhighlight lang="xml"> | |||
SELECT MAX(k COLLATE latin1_german2_ci) | |||
FROM t1; | |||
</syntaxhighlight> | |||
# 使用“DISTINCT”: | |||
#: <syntaxhighlight lang="xml"> | |||
SELECT DISTINCT k COLLATE latin1_german2_ci | |||
FROM t1; | |||
</syntaxhighlight> | |||
# 使用“WHERE”: | |||
#: <syntaxhighlight lang="xml"> | |||
SELECT * | |||
FROM t1 | |||
WHERE _latin1 'Müller' COLLATE latin1_german2_ci = k; | |||
</syntaxhighlight> | |||
#: <syntaxhighlight lang="xml"> | |||
SELECT * | |||
FROM t1 | |||
WHERE k LIKE _latin1 'Müller' COLLATE latin1_german2_ci; | |||
</syntaxhighlight> | |||
# 使用“HAVING”: | |||
#: <syntaxhighlight lang="xml"> | |||
SELECT k | |||
FROM t1 | |||
GROUP BY k | |||
HAVING k = _latin1 'Müller' COLLATE latin1_german2_ci; | |||
</syntaxhighlight> | |||
== “COLLATE”子句优先级 == | == “COLLATE”子句优先级 == |
2021年3月28日 (日) 05:24的版本
在 SQL 语句中使用“COLLATE”
使用“COLLATE”子句,您可以覆盖默认的默认排序规则以进行比较。“COLLATE”可用于 SQL 语句的各个部分。这里有些例子:
- 使用“ORDER BY”:【对中文排序呢???拼音升降序使用什么排序规则???】
SELECT k FROM t1 ORDER BY k COLLATE latin1_german2_ci;'''
- 使用“AS”:
SELECT k COLLATE latin1_german2_ci AS k1 FROM t1 ORDER BY k1;
- 使用“GROUP BY”:
SELECT k FROM t1 GROUP BY k COLLATE latin1_german2_ci;
- 具有聚合功能:
SELECT MAX(k COLLATE latin1_german2_ci) FROM t1;
- 使用“DISTINCT”:
SELECT DISTINCT k COLLATE latin1_german2_ci FROM t1;
- 使用“WHERE”:
SELECT * FROM t1 WHERE _latin1 'Müller' COLLATE latin1_german2_ci = k;
SELECT * FROM t1 WHERE k LIKE _latin1 'Müller' COLLATE latin1_german2_ci;
- 使用“HAVING”:
SELECT k FROM t1 GROUP BY k HAVING k = _latin1 'Müller' COLLATE latin1_german2_ci;