| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1340 人关注过本帖
标题:一个编程的问题,请各位看一看
只看楼主 加入收藏
tusi
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2006-12-10
收藏
 问题点数:0 回复次数:11 
一个编程的问题,请各位看一看

附件中有3个工作表,我想根据表1和表2的原始数据,通过编程得到表3的数据格式。请各位帮助。

I7S4JUvv.rar (1.98 KB) 一个编程的问题,请各位看一看


[此贴子已经被作者于2007-9-24 14:21:43编辑过]

搜索更多相关主题的帖子: 工作表 编程 
2007-09-24 14:20
purana
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:广东-广州
等 级:版主
威 望:66
帖 子:6039
专家分:0
注 册:2005-6-17
收藏
得分:0 
看了.但不知道你想做什么.

我的msn: myfend@
2007-09-24 14:28
tusi
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2006-12-10
收藏
得分:0 
回复:(purana)看了.但不知道你想做什么.
就是说我有2个原始表格:表1和表2,想通过SQL语句得到如表3的数据表格式。
2007-09-24 14:36
purana
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:广东-广州
等 级:版主
威 望:66
帖 子:6039
专家分:0
注 册:2005-6-17
收藏
得分:0 

if object_id('table1') is not null
drop table table1
if object_id('table2') is not null
drop table table2
if object_id('table3') is not null
drop table table3
go
create table table1(
psid int,
psnum int
)
insert into table1(psid,psnum)
select 8186000,8186000 union all
select 8186001,8186001 union all
select 8186002,8186002 union all
select 8186003,8186003 union all
select 8186004,8186004 union all
select 8186005,8186005 union all
select 8186006,8186006 union all
select 8186007,8186007 union all
select 8186008,8186008 union all
select 8186009,8186009 union all
select 8186010,8186010 union all
select 8186011,8186011 union all
select 8186012,8186012 union all
select 8186013,8186013 union all
select 8186014,8186014 union all
select 8186015,8186015 union all
select 8186016,8186016 union all
select 8186017,8186017 union all
select 8186018,8186018 union all
select 8186019,8186019
go

create table table2(
psid int
)
insert into table2(psid)
select 8186001 union all
select 8186005 union all
select 8186010 union all
select 8186014 union all
select 8186018

go
create table table3(
psid int,
psnum int
)
insert into table3(psid)
select 8186000 union all
select 8186001 union all
select 8186002 union all
select 8186003 union all
select 8186004 union all
select 8186005 union all
select 8186006 union all
select 8186007 union all
select 8186008 union all
select 8186009 union all
select 8186010 union all
select 8186011 union all
select 8186012 union all
select 8186013 union all
select 8186014 union all
select 8186015 union all
select 8186016 union all
select 8186017 union all
select 8186018 union all
select 8186019

go

update table3 set table3.psnum=(select table1.psnum from table1 where table1.psid=table2.psid)
from table2
where table3.psid=table2.psid

select * from table3


我的msn: myfend@
2007-09-24 15:09
tusi
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2006-12-10
收藏
得分:0 
回复:(purana)if object_id(\'table1\') is not null...

如果表1里面有很多数据,比如多达40万条,还是这样子做吗?

2007-09-24 15:28
purana
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:广东-广州
等 级:版主
威 望:66
帖 子:6039
专家分:0
注 册:2005-6-17
收藏
得分:0 
update table3 set table3.psnum=(select table1.psnum from table1 where table1.psid=table2.psid)
from table2
where table3.psid=table2.psid
你执行这个就行啊.
上面这次数据.我只是方便我测试而已.

我的msn: myfend@
2007-09-24 15:31
tusi
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2006-12-10
收藏
得分:0 
回复:(purana)update table3 set table3.psnum=(se...
谢谢!!!!!!!!!!!!!!!!!!1
2007-09-24 15:47
tusi
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2006-12-10
收藏
得分:0 
回复:(tusi)回复:(purana)update table3 set ta...
我怎么执行以后没有数据呢?可否将整个语句解释一下。。。
2007-09-24 16:00
purana
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:广东-广州
等 级:版主
威 望:66
帖 子:6039
专家分:0
注 册:2005-6-17
收藏
得分:0 
请问你是怎么执行的?
你的sql server数据库里是否有这三个Table.?

我的msn: myfend@
2007-09-24 16:04
tusi
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2006-12-10
收藏
得分:0 
回复:(purana)请问你是怎么执行的?你的sql server数...
我明白你的意思了,那可否对这个语句说明一下,我不太懂:

from table2
where table3.psid=table2.psid
2007-09-24 16:12
快速回复:一个编程的问题,请各位看一看
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012520 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved