mysql - 如何从通过选择获得的表中的一列中选择表名和值?
问题描述
对不起,听起来很复杂,但解释很简单。我猜答案没有。
在多站点 (WP) 中,我需要从所有名为 xxx_options 的表中的列中获取两个值。
我有脚本从两个模式(wp,wp2)中获取所有表:
SELECT table_name
FROM information_schema.tables
WHERE table_schema like 'wp%' and table_name like '%options';
我得到:
1 wp_11_options
2 wp_12_options
3 wp2_20_options
我有一个简单的查询来获取值:
SELECT option_value
FROM wp_10_options
WHERE option_name = 'siteurl'
我需要知道我在哪里有一个网站 URL,所以我需要类似的东西:
1 wp_11_options https://example1.org
1 wp2_12_options https://example4.org
或者我可以使用“option_value”中的两个值:
option_id = 1 and 49
或者
option_name = siteurl and upload_path (this file contain de number of the suffix, wp-**10**-options)
所以我可以得到:
1 example1.com wp-content/blogs.dir/10/files
我猜就像这个超级伪代码:
Select table_name as name, table_name.wp_option_value
From
(SELECT table_name
FROM information_schema.tables
WHERE table_schema like 'wp%' and table_name like '%options')
Order by table_name
模式:wp y wp2
表:LIKE '%options'
字段:option_id、option_name、option_value
值:option_id = 1 和 49 或 table_name 和 option_name = 'siteurl'
解决方案
推荐阅读
- javascript - 我不确定我是否正确地将 recapcha API 用于反应应用程序
- swift - Xcode 产生“分段错误:11”编译
- vb.net - SshNet 使用 ShellStream 读出第一个主机消息
- java - 如何使用 n,m,k 改进整数分区?
- python - 我有一个 CSV 文件,其中 A 列中的某些行是重复的,但我需要合并 B 列的内容
- ruby-on-rails - 在 Ruby/Rails 或 Faker 中生成一个范围内的随机小数
- android - 使用 Glide 同步获取图片
- html - 如何在 html 画布上将文本调整为精确的宽度?
- go - url 的 Gorilla Mux 正则表达式与完整的 url 不匹配
- java - 将 Java 应用程序(Azure 函数应用程序)从 2.x for GRADLE 迁移到运行时 3.x