0

我试图将字符串的一部分作为整数排序,CAST(pid AS SIGNED)但没有成功。

我想我需要这样的伪代码:CAST ON REGX('^islandora(/d?)$') OF pid AS SIGNED

doFields表具有以下结构:

+---------------+--------------+------+-----+---------+-------+
| Field         | Type         | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+-------+
| pid           | varchar(64)  | NO   | MUL | NULL    |       |
| ownerId       | varchar(255) | YES  |     | NULL    |       |
+---------------+--------------+------+-----+---------+-------+

这是样本数据:

+----------------+---------+
| pid            | ownerId |
+----------------+---------+
| islandora:1050 | 8       |
| islandora:1052 | 8       |
| islandora:1053 | 8       |
| islandora:1054 | 8       |
| islandora:1055 | 8       |
+----------------+---------+
4

3 回答 3

3

如何替换单词islandora:并将其转换为 int。

SELECT *
FROM tableName
ORDER BY CAST(REPLACE(pid, 'islandora:', '') AS SIGNED) ASC
于 2012-10-18T07:23:03.940 回答
2

试试这个:

order by 
       cast(substr(pid,locate(':',pid)+1) as SIGNED)    

如果整数部分始终为 4 个字母长度,则

  Order by
      cast(right(pid,4) as SIGNED)  
于 2012-10-18T07:22:47.080 回答
1

尝试使用此 ORDER BY -

ORDER BY SUBSTRING_INDEX(pid, ':', -1) * 1;
于 2012-10-18T07:32:04.203 回答