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
相关问答:
表中是这样,
部门号 部门信息
1 部门一
2 部门二
3 部门三
4& ......
sql server 2005 触发器 执行sp_executesql 的问题
db1,db2是一个服务器 server 的2个数据库
db1的table1 建立一个after update触发器 ,当 update table1 后建立一个复制表到 db2的tabl ......
'Select * into mytable from OpenDataSource(''Microsoft.JET.OLEDB.4.0'',''Data Source=f:\test.xls;Mode=Read;Extended Properties=Excel 5.0;Persist Security Info=False' ......
请帮忙看看怎么优化一下,该表数据约为66万,运行时间要19秒,SQL如下:
select DATEPART (hh ,Date_time ) as Hours ,
sum(Counts)*100.0/(Select sum(Counts) as total
&nbs ......
我系统式win7 ,数据库sqlserver2008.一直用windows验证,登陆,不能用sql验证,在sa上重新注册一个用户的话,登陆时第一遍报
已成功与服务器建立连接,但是在登录过程中发生错取。(provider:共享内存提供程序, ......