0
我想从table2更新table1与前面的1行与下面的SQL语句,但没有行更新即使有匹配。从table2更新table1与top1行
表1:
partno avprice
--------------
P001 0
P002 0
P003 0
P004 0
P005 0
表2:
id(PK) partno unitprice
-------------------------
1 P001 0.65
2 P001 0.90
3 P003 1.20
4 P005 0.25
5 P005 1.35
SQL
update table1
set avgprice = (select top 1 unitprice
from table2
left join table1 on table2.partno = table1.partno
order by tabl2.id)
错误:'t1'附近的语法不正确。期待SET。 –
我没有看到我的语法有问题。看看你是否可以让我的查询工作。 –
我刚刚将sql复制到sql server 2008 r2中的查询窗口。 table1和table2已经存在于数据库中。我仍然得到上述错误。 –