寻找支持,以确定编号是否返回到同一列的相同ID中的前一个编号。
下面是数据集的示例。
ID Number Date Sequence Count
10000B1 60 28.10.2015 10
10000B1 57 28.09.2015 9
10000B1 58 28.08.2015 8
10000B1 57 29.07.2015 7
10000B1 56 30.06.2015 6
10000B1 55 01.05.2015 5
10000B1 54 05.04.2015 4
10000B1 53 06.03.2015 3
10000B1 52 08.02.2015 2
10000B1 51 09.01.2015 1我想找出例外,如果在同一ID,号码再次回到以前的号码。
例如:序号为7的序号为57,序号为9的序号为57。
或者同一列中的数字从58而不是59返回到57。
您能在SQL中支持我使用SQL查找这些类型的案例吗?
谢谢。Ravi
发布于 2016-07-01 19:03:35
也许这就是你想要的:
select t.*
from Apple t
where exists (select 1
from Apple t2
where t2.id = t.id and
t2.number = t.number and
t2.sequence < t.sequence
);发布于 2016-07-01 19:04:31
你可以试试
select a.* from your_table as a
inner join your_table as b on a.date > b.date and a.number < b.number使用您的列名
a.ID, a.`Number`, a.`Date`, a.`Sequence Count`
from from apple_table as a
inner join apple_table as b on a.`Date` > b.`Date` and a.`number` < b.`number`对于编号和序列应该是
a.ID, a.`Number`, a.`Date`, a.`Sequence Count`
from from apple_table as a
inner join apple_table as b on a.`Sequence Count` < b.`Sequence Count` and a.`number` > b.`number`https://stackoverflow.com/questions/38143652
复制相似问题