我想取一个字段,搜索2个可能名称中的1个:cross
或memory
。根据它是哪一个,将其替换为相应的img。
我当前的代码(有效)如下:
SELECT REPLACE(column_name,'cross','<img src=\"crossimg.png\" />') AS 'column_name'
FROM my_table;
我希望它是这样的:
SELECT REPLACE(column_name, if == 'cross' then img1, elseif == 'memory' then img2) AS 'column_name'
FROM my_table;
答案 0 :(得分:1)
您可能正在寻找案例陈述:
SELECT case when column_name = 'cross' then img1
when column_name='memory' then img2
else column_name end as column_name from my_table;
答案 1 :(得分:0)
我想通了,我最终选择了:
$sql = "SELECT REPLACE(REPLACE(column_name,'second','<img src=\"secondimg.png\" />'),'first','<img src=\"firstimg.png\" />') AS column_name from my_table;