MySQL: select 在一组不同的 (char_length(text_column)) 记录中排名靠前

MySQL: select top result in a group of distinct(char_length(text_column)) records

我有一组记录,看起来像下面这些名义结果。计数列中的数字重复出现多次。 'count' 来自 char_length(text_column)。我想在每个这样的分组中获取第一条记录。我该怎么做呢?

我查看了 char_length() 文档并搜索了已完成此操作的示例,但找不到任何内容。

select distinct(char_length(text_column)), text_column from table

.. 与我能够得到的结果一样接近——这显然不是很接近。

=======+============================
 count +      text_column
=======+============================
2139   + some text entry
-------+----------------------------
3000   + another sentence here
-------+----------------------------
3000   + more text in this sentence
-------+----------------------------
3000   + still more text here
-------+----------------------------

谢谢, 体重

没有 "first" 这样的东西,除非列指定了顺序。但是,您可以使用 group by:

indeterminate 行中获取值
select char_length(text_column), text_column
from table
group by char_length(text_column);

我不太喜欢使用 group by 的 MySQL 扩展,其中 select 允许 text_column,但 group by 不允许].但是,因为它是一个长列,所以只让 MySQL 选择值可能比使用实际的聚合函数(例如 min()max())更有效。