排序以具有非连续的列值 [英] Sort to have non-consecutive column values

查看:66
本文介绍了排序以具有非连续的列值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在mysql查询中可能吗?当前数据表为:

is this possible in mysql queries? Current data table is:

id - fruit - name
1 - Apple - George
2 - Banana - George
3 - Orange - Jake
4 - Berries - Angela

名称列,我想对它进行排序,因此我的 select 查询中没有连续的名称。

In the name column, i would like to sort it so there is no consecutive name on my select query.

我希望输出的是名称栏中没有连续的 george

My desires output would be, no consecutive george in name column.

id - fruit - name
1 - Apple - George
3 - Orange - Jake
2 - Banana - George
4 - Berries - Angela

预先感谢。

推荐答案

在MySQL 8+中,您可以执行以下操作:

In MySQL 8+, you can do:

order by row_number() over (partition by name order by id)

在早期版本中,您可以使用变量来实现。

In earlier versions, you can do this using variables.

这篇关于排序以具有非连续的列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆