insert into 中的select子句有问题,
这个select col1,col2,col3 from a where b.col4=a.col4
语句中并没有B表的出现,你怎么能用B.col4=a.col4作条件呢。
这个select col1,col2,col3 from a where b.col4=a.col4
语句中并没有B表的出现,你怎么能用B.col4=a.col4作条件呢。
select a.col1,a.col2,a.col3 from a,b where b.col4=a.col4
我估计你的问题是
表a
col4 col1 col2 col3
1 ?? ?? ??
2 ?? ?? ??
3 ?? ?? ??
4 ?? ?? ??表b
col4 col1 col2 col3
1 null null null
2 null null null
3 null null null
4 null null null
你要把表a的移动到表b如果是这样的话,用update吧你还是说清楚你的目的吧,我瞎猜也不是办法。
就是把表b的数据按照col4相同的原则复制到表b
但是表b的col5,col6的数据不能变,是用update吧,怎么写?
顺便问一下,删除数据库的最后n行怎么写?
你的表a , b 分别有那些字段,究竟达到什么目的,能不能说详细点? 关于删除表的后N行数据,如果没有唯一的标识字段不好删,如果可以的话建议在这个表上加上一个 IDENTITY 的字段.
可以这样删最后N行workday 是表 XTworkday 的主键delete XTworkday where workday in (
select top 5 workday from XTworkday order by workday desc
)