订购 [英] ORDER BY

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

问题描述

我有这个列表,我通过units_unit_id订购,有没有办法我可以获得

a自然订单,这样D4和D5就可以在D12之前来了


谢谢,

马特


+ --------------- +

| units_unit_id |

+ --------------- +

| D1 |

| D12 |

| D14 |

| D15 |

| D16 |

| D18 |

| D19 |

| D4 |

| D5 |

+ --------------- +

I have this list that i''m ordering by units_unit_id and is there way I can get
a natural order so that D4 and D5 comes before D12

Thanks,
Matt

+---------------+
| units_unit_id |
+---------------+
| D1 |
| D12 |
| D14 |
| D15 |
| D16 |
| D18 |
| D19 |
| D4 |
| D5 |
+---------------+

推荐答案

Matias Silva写道:
Matias Silva wrote:
我有这个列表,我按unit_unit_id订购,有没有我可以获得
自然顺序,以便D4和D5来在D12之前
I have this list that i''m ordering by units_unit_id and is there way I
can get
a natural order so that D4 and D5 comes before D12




这不是一个自然的订单,自然顺序是你得到的。

简单的方法是改变表所以D和数字将在

不同的列中。另一种方法是使用一些字符串操作

函数将字符串解析为字符和数字然后按

数字排序。如果您的表中有很多行,这可能意味着查询速度慢。

所以如果可以的话,第一个解决方案会更好。


left()right( )和length()函数至少能够做到这一点。

我不确定是否有更好的方法,你可以找到这样的

手册中的功能:

http://dev.mysql.com/doc/mysql/en/String_functions.html


Matias Silva写道:
Matias Silva wrote:
我有这个列表,我通过units_unit_id订购,有没有我可以获得
自然顺序,以便D4和D5在D12之前出现
I have this list that i''m ordering by units_unit_id and is there way I
can get
a natural order so that D4 and D5 comes before D12




这不是一个自然的顺序,自然顺序是你得到的。

简单的方法是改变表格,使D和数字在

不同的列。另一种方法是使用一些字符串操作

函数将字符串解析为字符和数字然后按

数字排序。如果您的表中有很多行,这可能意味着查询速度慢。

所以如果可以的话,第一个解决方案会更好。


left()right( )和length()函数至少能够做到这一点。

我不确定是否有更好的方法,你可以找到这样的

手册中的功能:

http://dev.mysql.com/doc/mysql/en/String_functions.html


Matias Silva写道:
Matias Silva wrote:
我有这个列表,我通过units_unit_id订购,有没有我可以获得
自然顺序,以便D4和D5在D12之前出现
I have this list that i''m ordering by units_unit_id and is there way I
can get
a natural order so that D4 and D5 comes before D12




这不是一个自然的顺序,自然顺序是你得到的。

简单的方法是改变表格,使D和数字在

不同的列。另一种方法是使用一些字符串操作

函数将字符串解析为字符和数字然后按

数字排序。如果您的表中有很多行,这可能意味着查询速度慢。

所以如果可以的话,第一个解决方案会更好。


left()right( )和length()函数至少能够做到这一点。

我不确定是否有更好的方法,你可以找到这样的

手册中的功能:

http://dev.mysql.com/doc/mysql/en/String_functions.html


这篇关于订购的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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