`

Sybase tricky sql -- How to delete the earliest 2 records?

阅读更多

Table:

 

create table BE_TES_FEED (

    TRADE_STATUS VARCHAR(1) NOT NULL

    ,INSERT_DATE DATETIME NOT NULL

) lock datarows

go

 

Data:

 

INSERT INTO BE_TES_FEED VALUES ('1', getDate())

INSERT INTO BE_TES_FEED VALUES ('2', getDate())

INSERT INTO BE_TES_FEED VALUES ('3', getDate())

INSERT INTO BE_TES_FEED VALUES ('4', getDate())

INSERT INTO BE_TES_FEED VALUES ('5', getDate())

INSERT INTO BE_TES_FEED VALUES ('6', getDate())

INSERT INTO BE_TES_FEED VALUES ('7', getDate())

INSERT INTO BE_TES_FEED VALUES ('8', getDate())

INSERT INTO BE_TES_FEED VALUES ('9', getDate())

INSERT INTO BE_TES_FEED VALUES ('10', getDate())

 

sql:

 

DELETE FROM BE_TES_FEED

WHERE INSERT_DATE IN

(

SELECT INSERT_DATE

FROM BE_TES_FEED T2 

WHERE 2 > (SELECT COUNT(*) FROM BE_TES_FEED  T3 WHERE T3.INSERT_DATE < T2.INSERT_DATE)

)

 

The core idea:

 

Pay attention to the yellow part, and the data.

 

There is 0 record earlier than the 1 record.

There is 1 record earlier than the 2 record.

There are 2 records earlier than the 3 record.

… …

 

Show me all those records, with this number less than 2, and delete them!!

 

分享到:
评论

相关推荐

    微软内部资料-SQL性能优化3

    An intent lock indicates that SQL Server wants to acquire a shared (S) lock or exclusive (X) lock on some of the resources lower down in the hierarchy. For example, a shared intent lock placed at the ...

    RedGate.SQL.Prompt.v.5.1.8.2完美破解版

    SQL Prompt is crammed with features that take the routine out of working with SQL, and leave you to focus on the tricky bits. When you're writing code, SQL Prompt suggests appropriate keywords and ...

    RedGate.SQL.Prompt.v.5.2.2.1[带注册机(Keygen-Lz0)]

    SQL Prompt is crammed with features that take the routine out of working with SQL, and leave you to focus on the tricky bits. When you're writing code, SQL Prompt suggests appropriate keywords and ...

    Tricky-Track-3D

    《Tricky-Track-3D:C#编程在3D游戏开发中的应用探索》 "Tricky-Track-3D"这个项目显然是一款3D游戏,它的开发主要使用了C#编程语言。C#,全称C Sharp,是微软公司推出的一种面向对象的、运行于.NET Framework之上...

    RedGate SQL Prompt 5.1 with crack 破解版.

    SQL Prompt is crammed with features that take the routine out of working with SQL, and leave you to focus on the tricky bits. When you're writing code, SQL Prompt suggests appropriate keywords and ...

    iOS-2048-master

    Ideally, the AI should search from 0 depth to infinity and have a time out, it records the current best move when finish searching the current depth and stops immediately when timed out and return the...

    The GNU Make Book.pdf

    The GNU Make Book demystifies GNU make and shows you how to use its best features. You'll find a fast, thorough rundown of the basics of variables, rules, targets, and makefiles. Learn how to fix ...

    ng-book2-book-angular-6-r70

    ng-book2-book-angular-6该书最新版R70. This book aims to be the single most useful resource on learning Angular. By the time you’re done reading this book, you (and your team) will have everything you...

    Apple Pay Essentials(PACKT,2016)

    You will then learn how to determine whether the customer can use Apple Pay, and how to create payment requests. You will come to grips with designing a payment-processor program to interact with the...

    Wicked.Cool.PHP

    Once you know the basics of how the language works, wouldn't it be great to have a collection of useful scripts that solve those tricky problems and add interesting functionality to your site?...

    A First Course in Mathematical Analysis.pdf

    A First Course in Mathematical Analysis Mathematical Analysis (often called...through the tricky points. It is suitable for self study or use in parallel with a standard university course on the subject.

    Design Patterns in PHP and Laravel [2017]

    How to solve problems when using the patterns How to remember each pattern using mnemonics Who This Book Is For The person who will buy this book is likely using Laravel and PHP to do their job. ...

    英文原版-The Art of Scrum How Scrum Masters Bind Dev Teams and Unleash Agility 1st Edition

    This book covers the nuts and bolts of scrum—its framework, roles, team structures, ceremonies, and artifacts—from the scrum master’s perspective.The Art of Scrum details the scum master’s ...

    3000正则表达式

    ((19|20)[0-9]{2})-(([1-9])|(0[1-9])|(1[0-2]))-((3[0-1])|([0-2][0-9])|([0-9])) Validate the year month and day. 2008-12-15 ^1+0+$ A simple regular expression to determine if a subnet mask is contiguous...

    Wicked Cool PHP 英文原版

    Once you know the basics of how the language works, wouldn’t it be great to have a collection of useful scripts that solve those tricky problems and add interesting functionality to your site?...

Global site tag (gtag.js) - Google Analytics