您的位置:程序门 -> ms-sql server -> 基础类



求条sql语句


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


求条sql语句[已结贴,结贴人:xysoftzhk]
发表于:2007-04-18 15:31:17 楼主
表结构

sn   int,
id   int,
time   datetime
)
求   id=1、time最大的记录的sn
发表于:2007-04-18 15:32:341楼 得分:10
select   top   1   sn   from   表   where   id=1   order   by   time   desc
发表于:2007-04-18 15:33:312楼 得分:0
select  
        t.sn  
from  
        表   t  
where  
        t.id=1  
        and  
        not   exists(select   1   from   表   where   id=t.id   and   time> t.time)
发表于:2007-04-18 15:36:323楼 得分:0
select   id,max(b)   sn   from   [表]   where   id=1   group   by   id
发表于:2007-04-18 15:42:314楼 得分:5
:)
select   *   from   [表]   where   [time]=(select   max([time])   from   [表]   where   id=1   group   by   id)
发表于:2007-04-18 16:55:105楼 得分:5
select   sn
from   表
where   id=1   and   time=(select   max(time)   from   表   where   id=1   group   by   id)


快速检索

最新资讯
热门点击