【问题标题】:MYSQL Sorting Using Order byMYSQL 使用 Order by 排序
【发布时间】:2018-04-13 18:04:51
【问题描述】:

您好,我在排序 mysql 查询方面需要帮助。

我有一列,其中包含像

这样的数据

R_5_TP(6),
R_5_TP(7),
R_5_TP(8),
R_6_TP(1),
R_6_TP(10),
R_6_TP(6),
R_50_TP(1),
R_7_TP(1),

我需要使用 order by 编写一个选择查询并将结果作为

R_5_TP(6),
R_5_TP(7),
R_5_TP(8),
R_6_TP(1),
R_6_TP(6),
R_6_TP(10),
R_7_TP(1),
R_50_TP(1),

请帮忙。谢谢。

【问题讨论】:

  • 你试过什么?你得到什么错误? SO 不是代码生成器,我的朋友。

标签: mysql sql mssql-jdbc


【解决方案1】:

这有点棘手。我想你想要:

order by substring_index(substring_index(col, '_', 2), '_', -1) + 0,  -- convert middle value to a number
         substring_index(col, '(', -1) + 0 -- convert parenthesized value to number

【讨论】:

  • 它无法解决我的问题。它仅对括号内的整数进行排序,但是预期的排序顺序不同。
猜你喜欢
  • 2022-01-24
  • 1970-01-01
  • 1970-01-01
  • 2011-04-06
  • 2015-11-05
  • 1970-01-01
  • 1970-01-01
  • 2016-11-16
相关资源
最近更新 更多