SQL从另一个表插入到新表中

时间:2011-10-07 19:44:06

标签: sql select insert create-table

CREATE TABLE #Temporary
(
HoursThisYear int,
HoursLastYear int,
HoursBefore2010 int
)

INSERT 
INTO #Temporary (HoursThisYear)
SELECT SUM(Hours) WHEN Year = '2011' FROM WorkFlow

我很陌生,不知道我在做什么。

3 个答案:

答案 0 :(得分:1)

假设您正在寻找有关INSERT语法的帮助。

INSERT INTO #Temporary 
    (HoursThisYear)
    SELECT SUM(Hours) 
        FROM WorkFlow
        WHERE Year = '2011' 

答案 1 :(得分:0)

CREATE TABLE #Temporary ( HoursThisYear int, HoursLastYear int, HoursBefore2010 int )

INSERT INTO #Temporary (HoursThisYear) 
    SELECT SUM(Hours) 
    FROM WorkFlow
    WHERE Year = '2011' 

答案 2 :(得分:0)

这应该有效

CREATE TABLE #Temporary
(
HoursThisYear int,
HoursLastYear int,
HoursBefore2010 int
)

INSERT 
INTO #Temporary (HoursThisYear)
SELECT SUM(Hours) 
FROM WorkFlow
WHERE Year = '2011'