我有一个表 activity_types 包含活动的文本,例如
New project has been assigned to {user} with name {project}
New discussion has been posted by {client} on {project}
Project {project} has been closed by {user}
A draft has been approved by {client} on {project}
等等
我有另一个表格,其中填充了这些文本的 id。
现在我的要求是通过将 {} 中的文本替换为其实际值来获取这些内容,例如 {client} 应替换为客户端名称,{project} 应替换为项目名称。
我曾尝试使用嵌套的替换 mysql 函数,但它返回空字符串。这是我的查询
SELECT REPLACE(REPLACE(REPLACE(att.type_text, '{project}', p.project_business_name), '{user}', u.user_fullname), '{client}', c.client_name) AS activity, a.*
FROM activities a
LEFT JOIN activity_types AS att ON att.type_id = a.activity_type
LEFT JOIN users u ON u.user_id = a.activity_user AND a.activity_user IS NOT NULL
LEFT JOIN projects p ON p.project_id = a.activity_project AND p.project_is_removed = '0'
LEFT JOIN clients c ON c.client_id = a.activity_client AND a.activity_client IS NOT NULL;
问题是,如果我用静态文本替换 c.client_name 它可以正常工作,但是当我用 c.client_name 替换静态字符串时,它在没有 {client} 的活动中返回 null。任何猜测我在哪里做错了吗?