简体   繁体   English

SQL查询多个模式

[英]SQL querying multiple schemas

I am looking to run a query on several schemas in workbench. 我正在寻找在工作台中的几个架构上运行查询。 bascially, they are all symmetric , just different dates. 基本上,它们都是对称的,只是日期不同。 In workbench, i can only select one of them and run the query. 在工作台上,我只能选择其中之一,并运行查询。 Is there a way to aggregate them and run the query over a selection of schemas? 是否有聚集他们并经过选择模式的查询的方法吗?

EDIT: To elaborate a bit more, I have schemas with names yyyy_mm_dd for each day. 编辑:更详细地说明了一下,我有名字的模式yyyy_mm_dd的每一天。 Ideally, instead of doing a union over them as suggested by Guish below, If would like a dynamic query that would be able to turn the name of the schema into a valid date and Union all of them where the date is within a defined range. 理想的情况下,而不是对他们做一个工会通过以下Guish的建议,如果想动态查询,这将是能够把架构的名称为有效日期和联盟所有的人都在那里的日期是定义的范围内。 Is this possible? 这可能吗? I am using Oracle and sql workbench 我正在使用Oracle和sql工作台

I guess you are using mySql workbench. 我猜您正在使用mySql工作台。

Use an union operator. 使用union运算符。

(SELECT a FROM `schema1`.`t1` )
UNION
(SELECT a FROM `schema2`.`t1`);

Info here 这里的信息

You can then create a view from your query. 然后,您可以从查询中创建视图。

A thread here on querying multiple shema 一个线程在这里上查询多个玛

In know Transact-SQL a lot more and it is similar. 在已知的Transact-SQL上还有很多,并且类似。

SELECT ProductModelID, Name
FROM Schema1.ProductModel
UNION ALL
SELECT ProductModelID, Name
FROM Schema2.ProductModel
ORDER BY Name;

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

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