mysql查询在查询中添加单引号

标签 mysql

需要有关如何将以下查询结果转换为:的建议 在单引号中使用 philips、led 和 tv。

<强> insert into company_rawdata_split select 2,splits from (select NULL splits union select 'philips' union select 'led' union select 'tv') A where splits IS NOT NULL;

查询:

select concat
    ('insert into company_rawdata_split select ',id,',splits from (select NULL splits union select ',
    replace(complaint_against  ,' ',  ' union select '),') A where splits IS NOT NULL;'
    ) ProdCatQueries from company_rawdata_new

结果

insert into company_rawdata_split select 2,splits from (select NULL splits union select philips union select led union select tv) A where splits IS NOT NULL;

最佳答案

以下内容应该可以完成您正在尝试的事情。这只是巧妙地放置一些转义单引号 \'

的问题

select concat('插入company_rawdata_split select ',id,',splits from (select NULL splits union select\'',replace(complaint_against ,' ','\' union select\''),'\') A where splits IS NOT NULL;') 来自 company_rawdata_new 的 ProdCatQueries

关于mysql查询在查询中添加单引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22603782/

相关文章:

php - 自定义mysql按字段值排序

mysql - 在更新语句中设置变量值

java - 在从 Oracle 迁移到 MySQL 期间如何使用 Java 比较两者之间的数据

php - 带有从表 : layout issues 打开的表的 Bootstrap 模式

mysql - 微软 Access : Macro Button to download Table from MySQL

mysql - 删除子查询以提高性能

php - MySQL 查询不返回新插入的记录

MySQL 显示具有 x 条记录的表

php - MySQL:基于列值自动递增?

php - 多对多关系查询。拉维尔