奇妙的排序规则COLLATE

通过 COLLATE 子句,你可以在比较时覆盖替换掉任何默认collation, COLLATE 可以用
在SQL 语句的很多部分里,这里是一些例子:

1、在 ORDER BY 里:

select k
FROM t1
ORDER BY k COLLATE latin1_german2_ci;



2、在 AS 里:

select k COLLATE latin1_german2_ci AS k1
FROM t1
ORDER BY k1;



3、在GROUP BY里 :

select k
FROM t1
GROUP BY k COLLATE latin1_german2_ci;



4、在集合函数里:

select MAX(k COLLATE latin1_german2_ci)
FROM t1;



5、在DISTINCT里

select DISTINCT k COLLATE latin1_german2_ci
FROM t1;



6、在where 里:

select *
FROM t1
where _latin1 'Müller' COLLATE latin1_german2_ci = k;



7、在HAVING里:
select k
FROM t1
GROUP BY k
HAVING k = _latin1 'Müller' COLLATE latin1_german2_ci;

你可能感兴趣的:(排序)