在mysql表字段player_number
中接受3个字符 - 它可以只接受数字,仅接受字母或两者的组合,最多3个字母。
表格的条目如下,
TR
11
1
2
222
A
AA
有没有快速的方法来显示排序的“player_number”结果如下,
首选订单
1
2
11
222
A
AA
TR
替代方案:
A
AA
TR
1
2
11
222
答案 0 :(得分:2)
为了获得第一个首选订单:(首先是数字然后是字母)
SELECT
*
FROM YOUR_TABLE
ORDER BY
CASE WHEN player_number REGEXP '[0-9]+' THEN CAST(player_number AS UNSIGNED) END , player_number
为了获得替代首选订单:(先写信然后编号)
SELECT
*
FROM YOUR_TABLE
ORDER BY CAST(player_number AS UNSIGNED),player_number
答案 1 :(得分:1)
尝试以下内容;)
malformed_data = '{"malformed":"json"}'
test_response = self.client.post(self.url_create, malformed_data,
content_type="application/json")
<强> SQLFiddle DEMO HERE 强>