CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  MS-SQL Server >  疑难问题

一条超难解决的sql语句

楼主yinya00(yinya00)2005-08-04 14:34:14 在 MS-SQL Server / 疑难问题 提问

我有一张表里面有很多箱号的记录,每个不同的箱号分别都有多条记录,每条记录都有不同的更新时间,我怎么才能取出每个箱号最后一条更新的记录? 问题点数:100、回复次数:6Top

1 楼tangqijun199(撒旦.冲上了5角还差一个猩猩,继续努力……)回复于 2005-08-04 14:42:25 得分 0

select   *   from    
  t1   a,  
  (select   箱号,max(时间)   as   时间   from   t1   group   by   箱号)   b  
  where   a.箱号=b.箱号   and   a.时间=b.时间Top

2 楼coolingpipe(冷箫轻笛)回复于 2005-08-04 14:51:32 得分 0

select   *    
  from   t1   inner   join   (select   箱号,max(时间)   as   时间   from   t1   group   by   箱号)   t2  
                  on   t1.箱号=t2.箱号   and   t1.时间=t2.时间  
  Top

3 楼coolingpipe(冷箫轻笛)回复于 2005-08-04 14:52:09 得分 0

select   *    
  from   t1   inner   join   (select   箱号,max(时间)   as   时间   from   t1   group   by   箱号)   t2  
                  on   t1.箱号=t2.箱号   and   t1.时间=t2.时间  
  Top

4 楼phantomMan()回复于 2005-08-04 14:58:11 得分 0

create   table   a(  
  箱号   varchar(10),  
  更新时间   datetime  
  )  
   
  insert   into   a   values('001','2005-05-06')  
  insert   into   a   values('001','2005-05-05')  
  insert   into   a   values('001','2005-05-07')  
  insert   into   a   values('002','2005-05-05')  
  insert   into   a   values('002','2005-05-08')  
  insert   into   a   values('002','2005-05-09')  
  insert   into   a   values('003','2005-05-02')  
  insert   into   a   values('003','2005-05-05')  
   
  select   t1.*   from   a   t1  
  where   exists(  
  select   1   from   a   t2  
  where   t1.箱号=t2.箱号  
  having   max(t2.更新时间)=t1.更新时间  
  )Top

5 楼geniusqing(依帆)回复于 2005-08-04 14:58:40 得分 0

select   a.箱号,b.时间   from   t1   a,  
  (select   箱号,max(时间)   as   时间   from   t1   group   by   箱号)   b  
  where   a.箱号=b.箱号   and   a.时间=b.时间  
  Top

6 楼libin_ftsafe(子陌红尘:TS for Banking Card)回复于 2005-08-04 15:25:47 得分 0

select  
          a.*  
  from  
          表   a  
  where  
          not   exists(select   1   from   表   where   箱号=a.箱号   and   时间>a.时间)Top

相关问题

  • 超难度sql 语句
  • 超难度sql 语句
  • 超难度SQL语句
  • 超难度sql语句
  • 超难度sql语句
  • 求sql语句 超难!
  • 超难 求一sql语句!
  • 请教sql语句(超难)
  • 再问超难度sql语句
  • 高分求超难SQL语句!

关键词

  • 号
  • 时间
  • 更新
  • 记录
  • into a values
  • insert
  • max
  • group
  • select

得分解答快速导航

  • 帖主:yinya00

相关链接

  • SQL Server类图书

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo