表A里有H、M、S来表示时间,分表代表 时、分、秒怎么得出最小的时间?

解决方案 »

  1.   


    min是不是只能返回一个值?? 我有三个值要做比较,该怎么做呢
      

  2.   


    表A里有H、M、S来表示时间,分表代表 时、分、秒
    select min(convert(varchar(2),H)+'-'+convert(varchar(2),M)+'-'+convert(varchar(2),S)) from A
      

  3.   

    select min(S+M*60+H*3600) from [Table]
      

  4.   

    --> 数据库版本:
    --> Microsoft SQL Server 2008 (RTM) - 10.0.1600.22
    --> 测试数据:[TB]
    IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[TB]') 
    AND type in (N'U')) 
    DROP TABLE [TB]
    GO---->建表
    create table [TB]([H] int,[M] int,[S] int)
    insert [TB]
    select 12,34,44 union all
    select 11,23,33 union all
    select 10,22,33 union all
    select 10,22,22
    GO--> 查询结果
    SELECT *
    FROM [TB]  T 
    where NOT  exists 
    (select * from TB  where H <=T.H and M<=T.M  and S<T.S)
    --> 删除表格
    --DROP TABLE [TB]
      

  5.   

    select min(S+M*60+H*3600) from [Table]
    这个是对的,同时还有一个计算方式
    求出小时里最小的,然后求出最小小时集合里的最小的分,然后求出这个集合的最小的秒,就是你要的那条了
      

  6.   


    select min(right(cast(ltrim(h) as varchar,2) + 
           right(cast(ltrim(m) as varchar,2) + 
           right(cast(ltrim(s) as varchar,2))
    from tb
      

  7.   

    create table tb(H int,M int,S int)
    insert into tb values(1,2,3)
    insert into tb values(2,3,4)
    insert into tb values(11,12,13)
    insert into tb values(21,22,23)
    insert into tb values(21,12,13)
    insert into tb values(0,2,5)
    insert into tb values(9,12,38)
    goselect min('0'+right(cast(ltrim(h) as varchar),2) + 
           right('0'+cast(ltrim(m) as varchar),2) + 
           right('0'+cast(ltrim(s) as varchar),2))
    from tbdrop table tb/*
                  
    ------------- 
    000205(所影响的行数为 1 行)
    */
      

  8.   

    --取最小时间
    select * from #tb
        where not exists(select 1 from #tb t where #tb.H>=t.h and #tb.m>=t.m and #tb.s>t.s)
    --否定式,不存在这样的时分秒,时大于等于另一个时,分大于等于另一个分, 秒也大于另一个秒 ,即全部小于
    --那个等于必须加上
      

  9.   

    select t1.minH,t2.minM,t3.minS from #tb,
    (select min(h) minH from #tb) t1,
    (select min(m) minM from #tb) t2,
    (select min(s) minS from #tb) t3
    where #tb.h=t1.minh and #tb.m=t2.minM and #tb.s=t3.minS