今天遇到一個數(shù)據(jù)庫插入問題 向表中插入 生產(chǎn)狀態(tài) 為 2 的數(shù)據(jù) 但生產(chǎn)狀態(tài)為改為12 的所有數(shù)據(jù)
查看網(wǎng)上的評論
參考
insert into b (a,b,c) select ‘1’,‘2’,c from a where a=1
這樣就可以a,b字段是插入指定某個值,而C字段則用表a的c字段.
最后解決了。忽然想起原來也有這個問題
A 表和 B表類似,B中有1w條數(shù)據(jù),A表中只有部分B中的字段,如何把這1w條數(shù)據(jù)同步到A表中
?。。∽⒁?select 字段 不能加() 否則報錯 ERROR 1241 (21000): Operand should contain 1 column(s)文章來源:http://www.zghlxwxcb.cn/news/detail-653766.html
insert into A(字段a,字段b…) select 字段a,字段b… from B where 條件
eg: exampletest表有 id name status 字段 example表有id name status num money字段 有1000w條數(shù)據(jù),將example表中id介于1到1000的行插入到exampletest表中
insert into exampletest(name,status) select name,status from example where (id BETWEEN 1 AND 1000);文章來源地址http://www.zghlxwxcb.cn/news/detail-653766.html
到了這里,關(guān)于sql A表(含有部分B表字段) 向B表插入A表數(shù)據(jù)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!