`

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 ...

    expert_t_sql_window_functions_in_sql_server.pdf

    main benefit of window functions is the ease in which you can solve these tricky queries. Most of the time, you also realize a big boost in performance over the older methods. You can often use a ...

    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

    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 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...

    CCENT Certification All-In-One For Dummies.pdf

    information and tips to help you with tricky exam questions. You should understand everything that is in this book before taking the exam, but to identify key points that you must know, look for ...

    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...

    The.GNU.Make.Book.1593276494.

    GNU make is the most widely used build automation tool, but it can be challenging to master and its terse language can be tough to parse for even experienced programmers. Those who run into ...

    The.GNU.Make.Book.159327649

    GNU make is the most widely used build automation tool, but it can be challenging to master and its terse language can be tough to parse for even experienced programmers. Those who run into ...

    100 Go Mistakes and How to Avoid Them

    100 Go Mistakes and How ... As you go, you’ll navigate the tricky bits of handling JSON data and HTTP services, discover best practices for Go code organization, and learn how to use slices efficiently.

    Third-Party JavaScript

    They must adapt easily to unknown host environments, coexist with other applications, and manage the tricky security vulnerabilities you get when code and asset files are served from remote web ...

    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?...

    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 ...

    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 ...

    The Tangle Web

    Build mashups and embed gadgets without getting stung by the tricky frame navigation policy Embed or host user-supplied content without running into the trap of content sniffing For quick reference, ...

Global site tag (gtag.js) - Google Analytics