zoukankan      html  css  js  c++  java
  • SQL 查找重复项及批量修改数据成固定格式

    1、查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断
    select * from people
    where peopleId in (select   peopleId  from   people  group  by   peopleId  having  count(peopleId) > 1)

    2、删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有rowid最小的记录
    delete from people
    where peopleId  in (select   peopleId  from people  group  by   peopleId   having  count(peopleId) > 1)
    and rowid not in (select min(rowid) from   people  group by peopleId  having count(peopleId )>1)

    3、查找表中多余的重复记录(多个字段)
    select * from vitae a
    where (a.peopleId,a.seq) in   (select peopleId,seq from vitae group by peopleId,seq  having count(*) > 1)

    4、删除表中多余的重复记录(多个字段),只留有rowid最小的记录
    delete from vitae a
    where (a.peopleId,a.seq) in   (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
    and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)

    5、查找表中多余的重复记录(多个字段),不包含rowid最小的记录
    select * from vitae a
    where (a.peopleId,a.seq) in   (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
    and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
    6、把字段2013-5-1 批量改成2013-05-01
    UPDATE table
    A=convert(varchar(10),convert(datetime,A,120),120)

    7、数据库里时间自动计算公式(计算工龄)
    (case when dateadd(month,datediff(month,[JoinDate],getdate()),[JoinDate])>getdate() then ((((ltrim((datediff(month,[JoinDate],getdate())-(1))/(12))+'年')+ltrim((datediff(month,[JoinDate],getdate())-(1))%(12)))+'月')+ltrim(datediff(day,dateadd(month,datediff(month,[JoinDate],getdate())-(1),[JoinDate]),getdate())))+'天' else ((((ltrim(datediff(month,[JoinDate],getdate())/(12))+'年')+ltrim(datediff(month,[JoinDate],getdate())%(12)))+'月')+ltrim(datediff(day,dateadd(month,datediff(month,[JoinDate],getdate()),[JoinDate]),getdate())))+'天' end)

    8、Excel表里“条件查询”-“管理规划”
    =$D$4:$L$2856
    =AND($L4<4, $L4<>"")

  • 相关阅读:
    [HDU1087]Super Jumping! Jumping! Jumping!<dp>
    [codeforces]Page Numbers <模拟>
    [POJ1190]生日蛋糕<DFS>
    [HDU1029]Ignatius and the Princess IV<桶 水题>
    矩阵优化
    康复式训练
    bzoj1036 [ZJOI2008]树的统计Count
    luogu3761 [TJOI2017]城市
    bzoj2282 [SDOI2011]消防
    NOI2014
  • 原文地址:https://www.cnblogs.com/fanguiqin/p/3286784.html
Copyright © 2011-2022 走看看