关于mysql where子句的json字段

时间:2013-03-03 00:10:28

标签: mysql json select

如何获取包含apiData"method":"transfer"

内部的数据

我的字段名称是详细信息,它包含以下数据:

{"paymentMethodData":{"id":"3","api_id":"2","account_id":null,"account_ids":null,"installment_state":null,"name_1":"Havale"},"apiData":{"id":"2","method":"transfer","name":"Havale"}}

此查询有效但如果其他选项包含"method":"transfer",则会获得此查询。它不应该获取数据。如果它有apiData选项且位于"method":"transfer"内,则应该获得:

SELECT * FROM task_payment_actions AS tpa
INNER JOIN task_payment_action_detail AS tpad ON tpad.task_payment_action_id=tpa.id
WHERE tpad.detail REGEXP '(.*\"method\":\"transfer\".*)'

1 个答案:

答案 0 :(得分:0)

这应该有效 正如你所说的那样:“transfer”应该在apiData里面我根据你给定的字符串制作正则表达式。

REGEXP '.*"apiData":{[",a-zA-Z0-9]*"method":"transfer"'
REGEXP '.*"apiData":{[",a-zA-Z0-9]*"method":"transfer"[",a-zA-Z0-9]*}'