sql 语句
表A
卡号 时间
1 null
2 null
3 null
表B
卡号 时间
1 2008-1-6
1 2004-5-3
2 2005-5-6
3 2003-5-9
3 2001-2-3
问题:更新 表A里的 相应卡号的时间为 表B里相应卡号的(最小)时间
正确的结果:
1 2004-5-3(最小)
2 2005-5-6
3 2001-2-3(最小)
SQL code:
update a set
时间 = b.时间
from tb1 as a
join tb2 as b
on a.卡号= b.卡号
where not exists(select * from tb2
where 卡号=b.卡号 and 时间> b.时间)
SQL code:
update t set 时间=(select min(时间) from tb where 卡号=t.卡号) from ta t
SQL code
Code highlighting produced by
相关问答:
本人c#新手 可是要求要用c# ,sql2000开发c/s的工作流,一头雾水,请大家帮忙帮忙,给点思路,说的约具体越好,我也好往那个方面去学习
http://www.hxzi.com/view/61402.html
B/S版的,基本思想应该差不多的。。 ......
....接到一个小程序..工作原来大概是这样的...前台是WEB服务器.架构就是ASP+SQL..前台由ASP向SQL添加服务类别(表单).然后又后台程序读取表单..要实时读取..然后显示在服务器上面..从理论上面能行通不?如果可以..后台 ......
请帮忙看看怎么优化一下,该表数据约为66万,运行时间要19秒,SQL如下:
select DATEPART (hh ,Date_time ) as Hours ,
sum(Counts)*100.0/(Select sum(Counts) as total
&nbs ......
http://topic.csdn.net/u/20091008/12/a2577eba-1b5b-4e1e-ab20-0a047bf3f8d7.html?4385
1楼
liangCK
SQL code:
update a set
时间 = b.时间
from tb1 as a
join tb2 as b
on a.卡号= b.卡 ......