我是一名新手SQL学习者并试图像之前一样做一个更新语句
UPDATE STG
SET STG.COL1 = SUB.COL1
SET STG.COL2 = SUB.COL2
FROM TABLE AS STG
INNER JOIN (SELECT ID, MIN([DATE]) AS COL1, MAX([DATE]) AS COL2
FROM TABLE
GROUP BY ID) AS SUB ON STG.ID = SUB.ID
但我收到了这些错误:
Msg 170,Level 15,State 1,Line 4
第4行:'。'附近的语法不正确。Msg 156,Level 15,State 1,Line 10
关键字“AS”附近的语法不正确。
我正在使用
Microsoft SQL Server 2000 - 8.00.2066 (Intel X86)
May 11 2012 18:41:14
Copyright (c) 1988-2003 Microsoft Corporation
Enterprise Edition on Windows NT 5.2 (Build 3790: Service Pack 2)
答案 0 :(得分:1)
试试这个
UPDATE STG
SET STG.COL1 = SUB.COL1,STG.COL2 = SUB.COL2
FROM TABLE STG
INNER JOIN (SELECT ID
,MIN([DATE]) AS COL1
,MAX([DATE]) AS COL2
FROM TABLE
GROUP BY ID
) As SUB
ON STG.ID = SUB.ID