来自多个表的SQL简单查询

时间:2016-12-10 10:53:12

标签: sql

如果有人能帮我解决这个问题,我将不胜感激

我有4个SQL表。打开,高,低和关闭。

每个列都有2列,名为[Date],[Price]。

日期相同 - 但价格是数字而且不同。

我们如何进行查询,结果如下

[Date],[Open.Price],[High.Price],[Low.Price],[Close.Price]

3 个答案:

答案 0 :(得分:1)

SELECT Open_table.date,Open_table.Price,High_table.Price,low_table.Price,
       Close_table.Price
FROM Open_table
JOIN High_table ON Open_table.date = High_table.date
JOIN low_table ON Open_table.date = low_table.date
JOIN Close_table  ON Open_table.date = Close_table.date

答案 1 :(得分:0)

您可以尝试加入日期:

SELECT t1.[Date],
       t1.[Price] AS [Open.Price],
       t2.[Price] AS [High.Price],
       t3.[Price] AS [Low.Price],
       t4.[Price] AS [Close.Price]
FROM Open t1
INNER JOIN High t2
    ON t1.[Date] = t2.[Date]
INNER JOIN Low t3
    ON t2.[Date] = t3.[Date]
INNER JOIN Close t4
    ON t3.[Date] = t4.[Date]

答案 2 :(得分:0)

我在发布此问题后找到了另一种方法

SELECT 
EuropeOpen.[Date],EuropeOpen.[OCDO LN],EuropeHigh.[Date],EuropeHigh.[OCDO LN],EuropeLow.[Date],EuropeLow.[OCDO LN],
EuropeClose.[Date],EuropeClose.[OCDO LN]

FROM EuropeOpen,EuropeHigh,EuropeLow,EuropeClose

//如果您需要任何条件 WHERE ...