繁体   English   中英

MYSQL 从表中获取数据并使用变量插入新表

[英]MYSQL get data from table and insert on new table with variable

我需要获取表中的值以生成包含此值的 URL 并将其插入新表中。 是否可以使用 MySQL 中的变量来形成这个 URL?

例子:

SELECT `identity_id`, `email` FROM `identities` WHERE 1

Output:1个马塞洛@test.com

有了 ID 和 email,我需要在下面插入 HTML 内容,每个 ID 对应的 email 表示 VARIABLE。

INSERT INTO `identities`(`html_signature`) VALUES ([<img src="https://example.com/images/VARIABLE.png" width="580" height="138">])

感谢帮助

您可以使用select into语句

INSERT INTO `identities` (`html_signatures`)
  SELECT CONCAT("<img src=\"https://example.com/images/", `email`, ".png\" width=\"580\" height=\"138\">") as html_signatures
  FROM `identities` WHERE 1

我不确定VARIABLE是否代表 id、email 或两者,但您可以根据需要更改concat function arguments。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM