简体   繁体   English

在SQL中的2个表之间创建关系

[英]Creating relationship between 2 tables in SQL

I have these 2 tables and I need to create a relationship between them so that I can import them into SSAS Tabular and run some analysis. 我有这两个表,我需要在它们之间创建关系,以便可以将它们导入SSAS Tabular并进行一些分析。 The first table has RollingQuarter(Moving Quarter) data. 第一个表具有RollingQuarter(移动季度)数据。 The second is a basic Date table with Date as PK. 第二个是一个基本的Date表,其中Date为PK。 Can anyone suggest ways to create a relationship with these? 谁能建议与这些人建立关系的方法? Ill be using SQL Server 2012. 不适使用SQL Server 2012。

I could re-create a new date table also. 我也可以重新创建一个新的日期表。 在此处输入图片说明

I think you may have a rough time finding a relationship with these tables. 我认为您可能很难找到与这些表的关系。

Your top data table is derived data. 您最重要的数据表是派生数据。 It's an average over three months, reported monthly. 平均三个月以上,每月报告一次。 The Quantity column applies to that window, not to a particular date like all of the stuff in the second table. Quantity列适用于该窗口,不适用于特定日期,如第二个表中的所有内容。 So what would any relationship really mean? 那么,任何关系真正意味着什么?

If you have the primary data that were used to calculate your moving average, then use those instead. 如果您拥有用于计算移动平均值的主要数据,请改用这些数据。 Then you can relate dates between the two tables. 然后,您可以在两个表之间关联日期。

But if your analysis is such that you don't need the primary data for the top table, then just pick the middle of each quarter (March 15th 2001 for the first record) and use that as your independent variable for your time series on the top. 但是,如果您的分析不需要顶部数据表的主要数据,则只需选择每个季度的中间数据(第一个记录为2001年3月15日),然后将其用作时间序列上的自变量即可最佳。 Then you can relate them by that. 然后,您可以以此关联他们。

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

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