如何在内部联接的帮助下保存表格

时间:2016-10-07 18:46:22

标签: sql sql-server

大家好!我想在使用INNER JOIN后保存表格。

CREATE TABLE result AS (
SELECT  measures.Day,
SELECT  measures.Day,
    stations.Name,
    measures.name_measure,
    measures_of_stations.Count, 
    measures.unit
FROM
    measures_of_stations
    INNER JOIN
    stations
        ON measures_of_stations.id_station = stations.id_station
    INNER JOIN 
    measures
        ON measures_of_stations.id_measure = measures.id_measure)

但我有一个错误“旁边的语法无效(”。为什么? 提前谢谢你:)

2 个答案:

答案 0 :(得分:1)

您需要使用INTO子句,请参阅下面的示例:

SELECT  measures.Day,
    stations.Name,
    measures.name_measure,
    measures_of_stations.Count, 
    measures.unit INTO result
FROM
    measures_of_stations
    INNER JOIN
    stations
        ON measures_of_stations.id_station = stations.id_station
    INNER JOIN 
    measures
        ON measures_of_stations.id_measure = measures.id_measure

答案 1 :(得分:0)

SELECT  measures.Day,
    stations.Name,
    measures.name_measure,
    measures_of_stations.Count, 
    measures.unit
INTO result
FROM
    measures_of_stations
    INNER JOIN
    stations
        ON measures_of_stations.id_station = stations.id_station
    INNER JOIN 
    measures
        ON measures_of_stations.id_measure = measures.id_measure