Documentation Home
MySQL 8.3 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 40.8Mb
PDF (A4) - 40.9Mb
Man Pages (TGZ) - 294.0Kb
Man Pages (Zip) - 409.0Kb
Info (Gzip) - 4.0Mb
Info (Zip) - 4.0Mb
Excerpts from this Manual

MySQL 8.3 Reference Manual  /  ...  /  Using COLLATE in SQL Statements

12.8.1 在 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;