zoukankan      html  css  js  c++  java
  • 在没有主键的情况下定量删除数据!

    整行语句:

    select * from dbo.FreightRate where enabled=0 and createddate < (select max(createddate) as mx from (select top 100 createddate from dbo.FreightRate where order by createddate)a)

    分解说明:

    -- 按时间取前100条数据

    1.select top 100 createddate from dbo.FreightRate where order by createddate

    --取当前100条数据中最大的时间

    2.select max(createddate) as mx from (select top 100 createddate from dbo.FreightRate where order by createddate)a

    --再小于等于最大时间,注意一定要小于等于,才包括这个时间的全部数据

    3.Delete from dbo.FreightRate where createddate <= (select max(createddate) as mx from (select top 100 createddate from dbo.FreightRate where order by createddate)a)

    缺点:此方法是通知读取一定范围内的最大时间来确定数据集大小的。因此不一定总是前面子查询中的TOP100,实际会大于此数据集。本查询不适用于大量相同值的createddate表,否则就此方法定量也无从谈起。

  • 相关阅读:
    设计模式
    WCF 4 安全性和 WIF 简介
    锁,性能调优
    javascript 异步
    javascript的回调函数
    HTML 5 简介
    CSS3 教程
    implementation of python string
    Extending Python with C or C++
    python,deep copy,shallow copy
  • 原文地址:https://www.cnblogs.com/stangray/p/1875434.html
Copyright © 2011-2022 走看看