如何正确编写这个mysql查询?

时间:2014-03-19 16:27:33

标签: mysql

如何正确编写这个mysql查询?

SELECT order_id FROM order_details WHERE tracking_id = substr('420342389400110200882112625820',-LENGTH(tracking_id))

查询应与tracking_id匹配42034238 9400110200882112625820

提前致谢

2 个答案:

答案 0 :(得分:2)

尝试使用RIGHT功能:

SELECT order_id
FROM order_details
WHERE tracking_id = RIGHT('420342389400110200882112625820',LENGTH(tracking_id))

答案 1 :(得分:0)

SELECT order_id
FROM order_details
WHERE tracking_id = RIGHT('420342389400110200882112625820',LENGTH(tracking_id))
  

MySQL RIGHT()从右侧提取指定数量的字符   一边的字符串。

参考MySQL RIGHT()