多表update问题,在线等。

mathematician 2007-06-18 02:51:47
表fm,fl表为父子表

表fm pk(id)
id range
200610001 null
200610002 null
200610003 null

表fl pk(id,pno)
id pno dno
200610001 1 2006Y0012
200610001 2 2006Y0013
200610001 3 2006Y0014
200610001 4 2006Y0015
200610002 1 2006Y0016
200610002 2 2006Y0017
200610003 1 2006Y0018

现在要求更新fm表,是range为如下形式:
id range
200610001 2006Y0012-2006Y0015
200610002 2006Y0016-2006Y0017
200610003 2006Y0018-2006Y0018

非常着急,请各位帮忙。谢谢!
...全文
377 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
mathematician 2007-06-18
  • 打赏
  • 举报
回复
谢谢各位!马上结帖!谢谢!
fwacky 2007-06-18
  • 打赏
  • 举报
回复
create table fm( id varchar(10), range varchar(50))
insert fm
select '200610001', null
union select '200610002', null
union select '200610003' , null
go
create table pk(id varchar(10), pno int , dno varchar(10))

insert pk
select '200610001', 1 ,'2006Y0012'
union select '200610001', 2 ,'2006Y0013'
union select '200610001', 3 ,'2006Y0014'
union select '200610001', 4 ,'2006Y0015'
union select '200610002', 1 ,'2006Y0016'
union select '200610002', 2 ,'2006Y0017'
union select '200610003', 1 ,'2006Y0018'



select * from fm
select * from pk

update fm set range = B.dno from fm,(select id , min(dno) +'-' + max(dno) as dno from pk group by id) B where B.id = fm.id



/*
id range
---------- --------------------------------------------------
200610001 2006Y0012-2006Y0015
200610002 2006Y0016-2006Y0017
200610003 2006Y0018-2006Y0018

*/

肥胖的柠檬 2007-06-18
  • 打赏
  • 举报
回复
create table #aa (id int, pno int, dno varchar(20))
insert into #aa
select 200610001 , 1 , '2006Y0012' union all
select 200610001 , 2 , '2006Y0013' union all
select 200610001 , 3 , '2006Y0014' union all
select 200610001, 4 , '2006Y0015' union all
select 200610002, 1 , '2006Y0016' union all
select 200610002 , 2 , '2006Y0017' union all
select 200610003 , 1 , '2006Y0018'
select b.id,(select dno from #aa where a.id=id and pno=a.p1)+'-'+(select dno from #aa where a.id=id and pno=a.p2)
from
(
select id,max(pno) p1,min(pno) p2 from #aa group by id
) a
---------------------------------------------------------------
update fm set range =
(select dno from #aa where a.id=id and pno=a.p1)+'-'+(select dno from #aa where a.id=id and pno=a.p2)
from
(
select id,max(pno) p1,min(pno) p2 from #aa group by id
) a ,b where a.id=b.id
GEPIN 2007-06-18
  • 打赏
  • 举报
回复
update fm
set range = b.dno + '-' + c.dno
from fm a
outer apply(
select top 1 dno
from fl
where id = a.id
order by pno
)b
outer apply(
select top 1 dno
from fl
where id = a.id
order by pno desc
)c
leo_lesley 2007-06-18
  • 打赏
  • 举报
回复

create table fm( id varchar(10), range varchar(50))
insert fm
select '200610001', null
union select '200610002', null
union select '200610003' , null
go
create table pk(id varchar(10), pno int , dno varchar(10))
insert pk
select '200610001', 1 ,'2006Y0012'
union select '200610001', 2 ,'2006Y0013'
union select '200610001', 3 ,'2006Y0014'
union select '200610001', 4 ,'2006Y0015'
union select '200610002', 1 ,'2006Y0016'
union select '200610002', 2 ,'2006Y0017'
union select '200610003', 1 ,'2006Y0018'

update fm set range=(select min(dno)+'-'+max(dno) from pk where id=fm.id)

select * from fm


drop table fm,pk

/*
id range
---------- --------------------------------------------------
200610001 2006Y0012-2006Y0015
200610002 2006Y0016-2006Y0017
200610003 2006Y0018-2006Y0018

*/
hongqi162 2007-06-18
  • 打赏
  • 举报
回复
select id ,min(dno)+'-'+max(dno) as range from ttt group by id


1 200610001 2006Y0012-2006Y0015
2 200610002 2006Y0016-2006Y0017
3 200610003 2006Y0018-2006Y0018
friendliu 2007-06-18
  • 打赏
  • 举报
回复
declare @id varchar(20)
declare @range varchar(30)
DECLARE fm_cursor CURSOR
FOR SELECT * FROM fm
OPEN fm_cursor
FETCH NEXT FROM fm_cursor into @id
WHILE @@FETCH_STATUS = 0
begin
select @range=min(dno)+'-'+max(dno) from fl where id=@id
update fm set range=@range where id=@id
FETCH NEXT FROM fm_cursor into @id
end
CLOSE fm_cursor
DEALLOCATE fm_cursor

子陌红尘 2007-06-18
  • 打赏
  • 举报
回复
create table fm(id varchar(10),range varchar(40))
insert into fm values('200610001',null)
insert into fm values('200610002',null)
insert into fm values('200610003',null)

create table fl(id varchar(10),pno int,dno varchar(10))
insert into fl values('200610001',1,'2006Y0012')
insert into fl values('200610001',2,'2006Y0013')
insert into fl values('200610001',3,'2006Y0014')
insert into fl values('200610001',4,'2006Y0015')
insert into fl values('200610002',1,'2006Y0016')
insert into fl values('200610002',2,'2006Y0017')
insert into fl values('200610003',1,'2006Y0018')

update t
set
range= (select dno from fl f where f.id=t.id and not exists(select 1 from fl where id=f.id and pno<f.pno))
+'-'+(select dno from fl f where f.id=t.id and not exists(select 1 from fl where id=f.id and pno>f.pno))
from
fm t

select * from fm
/*
id range
---------- ----------------------------------------
200610001 2006Y0012-2006Y0015
200610002 2006Y0016-2006Y0017
200610003 2006Y0018-2006Y0018
*/


drop table fm,fl
chuifengde 2007-06-18
  • 打赏
  • 举报
回复
update fm set range=x from fm,(select id, min(dno)+'-'+max(dno) x from fl group by id) bb where fm.id=bb.id
内容概要:本文针对无刷直流电机驱动的电子机械制动(EMB)执行器,建立了考虑Stribeck摩擦特性的非线性耦合动力学模型,并在Simulink环境中完成了系统级仿真分析。研究综合集成了电机动力学、齿轮传动机构与制动执行机构的动力学特性,构建了高保真的机电一体化系统模型。重点引入Stribeck摩擦模型以精确描述低速工况下执行器内部存在的静摩擦、粘滞摩擦与库仑摩擦之间的过渡行为,有效提升了系统在启停、反向运动等瞬态过程中的动态响应仿真精度。通过多工况仿真验证了模型的有效性,能够准确反映摩擦引起的爬行、滞后与定位误差等非线性现象,为EMB系统的高性能控制算法设计(如摩擦补偿、滑模控制)与结构优化提供了高可信度的仿真平台。; 适合人群:从事汽车电子制动系统、电机驱动控制、机电系统建模与仿真研究的研究生、科研人员及工程技术人员,需具备扎实的机械动力学、自动控制理论基础和MATLAB/Simulink仿真能力。; 使用场景及目标:①用于高精度电子机械制动系统的设计验证与性能预测;②为消除摩擦非线性影响的先进控制策略(如自适应控制、智能控制)提供精确的被控对象模型;③深入探究Stribeck摩擦等非线性因素对系统动态性能(如响应延迟、稳态误差)的作用机理; 阅读建议:读者应结合提供的Simulink模型文件,深入剖析Stribeck摩擦模块的数学实现与参数辨识方法,建议通过改变输入指令(如阶跃、正弦)和负载条件进行对比仿真,以直观理解非线性摩擦对系统动态特性的影响。

34,875

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧