位置:首頁 > 軟件操作教程 > 數(shù)據(jù)分析 > SQL > 問題詳情

SQL操作應用——兩個表的內(nèi)容之和

提問人:ylm發(fā)布時間:2020-09-28

[id] 編號 自動編號
[name] 名稱 文本
[price] 價格 數(shù)字
[guige] 規(guī)格 文本
[changjia] 生產(chǎn)廠家 文本
[baozhuang] 包裝 文本
[danwei] 單位 文本
[xingzhi] 性質(zhì) 文本

1.這樣
-----------------------------
insert into c(id,name,.....)
select id,name,.....
from a
insert into c(id,name,.....)
select max(id)+1,name,.....
from b
------------------------------
2.更正:
如果直接在查詢分析器里執(zhí)行:
-------------------------------
insert into c(name,.....)
select name,.....
from a
insert into c(name,.....)
select name,.....
from b
--------------------------------
3.用union方法
---------------------------------
insert into [c] ([id] ,編號,自動編號)
select [id],編號,自動編號 from [a]
union
select [id],編號,自動編號 from [b]
-----------------------------------
4.asp的解決辦法
------------------------------------------------------------
<% '循環(huán)檢測a表
Set rs = Server.CreateObect("ADODB.RECORDSET")
rs.open "select * from a order by id",conn,1,1
Do while not rs.eof
Call actAdd(rs("name")) '調(diào)用像b表添加內(nèi)容的函數(shù)!
rs.MoveNext
Loop
rs.Close
Set rs = Nothing

Sub actAdd(txt)
Dim ts, sql
sql = "insert into b(name) values('"& txt &"')"
Set ts = Conn.Execute(sql)
ts.Close
Set ts = Nothing
end Sub
%>
------------------------------------------------------------------
5.asp的解決辦法
-----------------------------------------------------------------------------------
<%
dim arr_temp1,arr_temp2,arr_data
set rs=conn.execute("select id,name,price,guige,changjia,baozhuang,danwei from a")
arr_temp1=rs.getrows
rs.close
set rs=nothing

set rs=conn.execute("select id,name,price,guige,changjia,danwei,xingzhi from b")
arr_temp2=rs.getrows
rs.close
set rs=nothing

rem 開始處理
redim arr_data(ubound(arr_temp1,2)+ubound(arr_temp2,2),7)
rem 把兩個數(shù)組的內(nèi)容復制進來
這一部分自己寫了做兩個循環(huán)
然后再存進數(shù)據(jù)庫
%>


繼續(xù)查找其他問題的答案?

相關視頻回答
回復(0)
返回頂部