zoukankan      html  css  js  c++  java
  • SQL——多条相似内容只取一条

    代码

    --sql多条相似内容取一条
    
    --首先创建测试数据
    if object_id('tempdb..#t') is not null drop table #t
    
    create table #t
    (
        time int,
        total int,
        name varchar(50)
    )
    
    insert into #t values (100,1000,'zhangsan')
    insert into #t values (100,1001,'lisi')
    insert into #t values (100,1002,'wangwu')
    insert into #t values (101,1003,'zhaoliu')
    insert into #t values (101,1004,'sunqi')
    insert into #t values (102,1005,'hello')
    
    select * from #t
    
    --取一条--取的是total最大的
    select * from #t as a 
    where not exists(
        select 1 
        from #t 
        where a.time = time 
            and a.total <total)
  • 相关阅读:
    lightoj-1050
    lightoj-1305
    lightoj-1354
    lightoj-1433
    lightoj-1227
    lightoj-1189
    lightoj-1182
    lightoj-1011
    lightoj-1009
    lightoj-1023
  • 原文地址:https://www.cnblogs.com/fabao/p/12827703.html
Copyright © 2011-2022 走看看