http://topic.csdn.net/u/20091008/12/a2577eba-1b5b-4e1e-ab20-0a047bf3f8d7.html?4385
1楼
liangCK
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.时间)
3楼
liangCK
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.时间)
当时我没有看到3楼的正解,于是就发了一个帖子
http://topic.csdn.net/u/20091008/13/490b3e82-3e4c-4e7d-a5a1-a2632e355bd8.html?32712看来 wufeng4552 xuejie09242 navy887
都没有看到 帖子中的错误啊
1楼
liangCK
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.时间)
3楼
liangCK
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.时间)
当时我没有看到3楼的正解,于是就发了一个帖子
http://topic.csdn.net/u/20091008/13/490b3e82-3e4c-4e7d-a5a1-a2632e355bd8.html?32712看来 wufeng4552 xuejie09242 navy887
都没有看到 帖子中的错误啊
1 2007 1 2007
1 2008 1 2008
1 2004 1 20042007 = <all N
2008 = <all n
2004 = <all n 应该是把比最小的都排除掉
比如
2007>(2007 2008 2004) y
2008>(2007 2008 2004) y
2004>(2007 2008 2004) n
卡号 时间
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(最小)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.时间)
时间= b.时间from tb1as ajoin tb2as bon a.卡号= b.卡号where not exists(select*from tb2where 卡号=b.卡号 and 时间> b.时间)
> 错了啊