WHERE 技能=VB ) AND 技能=PHP
三数据库合并问题
access里的两个表想让两个表的内容合并
表[a]结构如下:
[id]编号自动编号
[name]名称文本
[price] 价格数字
[guige] 规格文本
[changjia]生产厂家文本
[baozhuang] 包装文本
[danwei]单位文本
共有条记录除了id和name字段其他均可以为空
表结构如下:
[id]编号自动编号
[name]名称文本
[price] 价格数字
[changjia]生产厂家文本
[danwei]单位文本
[xingzhi] 性质文本
共有条记录除了id和name字段比表[a]少几个字段但还多一个[xingzhi]的字符安其它均可以为空
现在想生成一个新表[c]结构如下而且内容是两个表的内容之和
[id]编号自动编号
[name]名称文本
[price] 价格数字
[guige] 规格文本
[changjia]生产厂家文本
[baozhuang] 包装文本
[danwei]单位文本
[xingzhi] 性质文本
用sql语句也可以手工操作也好xml也好别管怎么着吧怎么实现呀哥们要郁闷坏了真要让我们再输入条记录我就挂了
回答:
这样
insert into c(idname)
select idname
from a
insert into c(idname)
select max(id)+name
from b
更正
如果直接在查询分析器里执行
insert into c(name)
select name
from a
insert into c(name)
select name
from b
用union方法
insert into [c] ([id] 编号自动编号)
select [id]编号自动编号 from [a]
union
select [id]编号自动编号 from
asp的解决办法
<% 循环检测a表
Set rs = ServerCreateObect(ADODBRECORDSET)
rsopen select * from a order by idconn
Do while not rseof
Call actAdd(rs(name))调用像b表添加内容的函数!
rsMoveNext
Loop
rsClose
Set rs = Nothing
Sub actAdd(txt)
Dim ts sql
sql = insert into b(name) values(& txt &)
Set ts = ConnExecute(sql)
tsClose
Set ts = Nothing
end Sub
%>
asp的解决办法
<%
dim arr_temparr_temparr_data
set rs=connexecute(select idnamepriceguigechangjiabaozhuangdanwei from a)
arr_temp=rsgetrows
rsclose
set rs=nothing
set rs=connexecute(select idnamepriceguigechangjiadanweixingzhi from b)
arr_temp=rsgetrows
rsclose
set rs=nothing
rem 开始处理
redim arr_data(ubound(arr_temp)+ubound(arr_temp))
rem 把两个数组的内容复制进来
这一部分自己写了做两个循环
然后再存进数据库
%>
最后转一些经典的SQL语句:
蛙蛙推荐一些精妙的SQL语句
说明复制表(只复制结构源表名a 新表名b)
SQL: select * into b from a where <>
说明拷贝表(拷贝数据源表名a 目标表名b)
SQL: insert into b(a b c) select def from b;
说明显示文章提交人和最后回复时间
SQL: select atitleausernamebadddate from table a(select max(adddate) adddate from table where tabletitle=atitle) b
说明外连接查询(表名a 表名b)
SQL: select aa ab ac bc bd bf from a LEFT OUT JOIN b ON aa = bc
说明日程安排提前五分钟提醒
SQL:select * from 日程安排 where datediff(minutef开始时间getdate())>
说明两张关联表删除主表中已经在副表中没有的信息
SQL:
delete from info where not exists ( select * from infobz where infoinfid=infobzinfid )
说明
SQL:
SELECT ANUM ANAME BUPD_DATE BPREV_UPD_DATE
FROM TABLE
(SELECT XNUM XUPD_DATE YUPD_DATE PREV_UPD_DATE
FROM (SELECT NUM UPD_DATE INBOUND_QTY STOCK_ONHAND
FROM TABLE
WHERE TO_CHAR(UPD_DATEYYYY/MM) = TO_CHAR(SYSDATE YYYY/MM)) X
(SELECT NUM UPD_DATE STOCK_ONHAND
FROM TABLE
WHERE TO_CHAR(UPD_DATEYYYY/MM) =
TO_CHAR(TO_DATE(TO_CHAR(SYSDATE YYYY/MM) ¦¦ /YYYY/MM/DD) YYYY/MM) ) Y
WHERE XNUM = YNUM (+)
AND XINBOUND_QTY + NVL(YSTOCK_ONHAND) <> XSTOCK_ONHAND ) B
WHERE ANUM = BNUM
说明
SQL:
select * from studentinfo where not exists(select * from student where studentinfoid=studentid) and 系名称=&strdepartmentname& and 专业名称=&strprofessionname& order by 性别生源地高考总成绩
说明
从数据库中去一年的各单位电话费统计(电话费定额贺电化肥清单两个表来源)
SQL:
SELECT auserper atel astandfee TO_CHAR(atelfeedate yyyy) AS telyear
SUM(decode(TO_CHAR(atelfeedate mm) afactration)) AS JAN
SUM(decode(TO_CHAR(atelfeedate mm) afactration)) AS FRI
SUM(decode(TO_CHAR(atelfeedate mm) afactration)) AS MAR
SUM(decode(TO_CHAR(atelfeedate mm) afactration)) AS APR
SUM(decode(TO_CHAR(atelfeedate mm) afactration)) AS MAY
SUM(decode(TO_CHAR(atelfeedate mm) afactration)) AS JUE
SUM(decode(TO_CHAR(atelfeedate mm) afactration)) AS JUL
SUM(decode(TO_CHAR(a
上一篇:从ORACLE向SQL SERVER定时迁移作业的设计与实现
下一篇:SQL Server成为低成本建实用数据库的首选 |