易截截图软件、单文件、免安装、纯绿色、仅160KB

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


相关问答:

sql server 存储过程循环赋值的问题

小弟是个新手 现在有个问题一直不能解决
例如
procedure produce_proc
    @p001 nvarchar(8000),
    @p002 nvarchar(8000),
    @p003 nvarchar(8000),
  & ......

两张字段相同表,求SQL语句,谢谢大家

有两张字段相同的表A,B。字段为SN, Name, Operator, Result, Remark
A表中字段SN唯一,B表中字段SN不唯一,有很多条
如何用一条select语句
把符合SN=’abc’的记录从A,B表中筛选出来?



SQL co ......

xml导入sql数据库,急

各位大侠,我有一个xml文件
XML code:

<?xml version="1.0" encoding="GB2312"?>
<FileId fileid="86">
<ResultSet>
<row id="0">
......

oracle中的to_char,sql server 2005对应的方法是什么

怎么把下面的改成sql server的方法?
to_char(img_comm_metadata.scene_centre_time,'yyyy-mm-dd hh24:mm:ss')>='1990-10-13 09:41:20'
SQL code:
datediff(ss,'1990-10-13 09:41:20',img_ ......

SQL 优化求助

请帮忙看看怎么优化一下,该表数据约为66万,运行时间要19秒,SQL如下:

select DATEPART (hh ,Date_time ) as Hours ,
sum(Counts)*100.0/(Select sum(Counts) as total
      &nbs ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号