MySQL - 是否可以使用列作为表名?
假设我们在 mysql 中有一个表“mytable”,
其中包含以下列:id、title、type
。
是否可以在同一查询中使用其列作为表名?
例如:
SELECT m.id, m.title FROM mytable m INNER JOIN m.type WHERE m.id=2
其中“type”将为我提供进行内部联接的表的名称。
Suppose that we have, in mysql, a table "mytable"
with the columns: id, title, type
.
Is it possible to use its column as a table name in the same query?
For example:
SELECT m.id, m.title FROM mytable m INNER JOIN m.type WHERE m.id=2
Where "type" will give me the name of the table to do the inner join.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,对不起 :(
你能得到的最接近的(据我所知)是光标浏览你的主表并为每行的连接编写动态 html。非常慢。
或者,找到一个新的设计模式 - 你是否有空间发布关于您想要实现什么目标以及人们如何实现这一目标的问题?
No, Sorry :(
The closest you can get (afaik) is to cursor through your main table and write dynamic html for the join for each row. VERY slow.
Or, find a new design pattern - Is there scope for you to post a question about what you are trying to achieve and how people may go about that?
为什么不将所有类型数据放在一个表中?然后按类型对表进行分区。
Why not put all of your type data in a single table ? and then partition the table by type.