达到条件时如何跳过其他更多记录? [英] How to skip with other further records when reached condition?

查看:157
本文介绍了达到条件时如何跳过其他更多记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有SQL问题。假设我们有记录:

I have SQL issue. Lets suppose we have record:

< img src = https://i.stack.imgur.com/bFNnZ.png alt = records>

在上面的记录中,我们需要以选择取消的记录,但只有2个不是全部都以 Cancel 开头的记录。顶部或任何地方可能会有多个取消

In above record we need to select record with Cancel but only 2 starting not all with Cancel. There may be multiple Cancel on Top or anywhere.

请帮助我为此创建查询。

Please help me to create query for that.

推荐答案

不存在

select t.* from tablename t
where col = 'Cancel'
  and not exists (
  select 1 from tablename
  where creation_date < t.creation_date and col <> t.col
)  

请参见演示

这篇关于达到条件时如何跳过其他更多记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆