簡體   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