日期差异记录 [英] Date difference records

查看:90
本文介绍了日期差异记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为Customers的表,这个表有CustomerName,Order和Order Date:


Customer1 Order A 1/1/2006

订购B 1/6/2006

订单C 1/1/2009


客户2订单A 1/1/2007

订购B 1/1/2010

订单C 1/6/2010


我们对订单日期差异超过两年的记录不感兴趣。换句话说,我们只保留他们的订单在两年内发生的记录。例如:在上述情况下,我们可以保留Customer1,订单A,2006年1月1日,因为在不到两年的时间内就有订单。对于客户1,订单B 1/6/2006也是如此,因为不到2年前有订单。但是,我们不应该保留Customer1,订单C,2009年1月1日,因为在两年的时间跨度内(之前和之后)没有订单。所以我们从表中删除它。


客户2的相同逻辑,即客户2,订单A,1/1/2007的第一条记录将被删除。


我不知道如何实现这一点,任何人都可以帮助我吗?我真的很感激。


谢谢,

I have a table called Customers, This table has CustomerName, Order, and Order Date:

Customer1 Order A 1/1/2006
Order B 1/6/2006
Order C 1/1/2009

Customer2 Order A 1/1/2007
Order B 1/1/2010
Order C 1/6/2010

We are not interested in records that their Order date difference is more than two years. In other words we only keep records that their order happens in two year period. For example: in the above situation, we can keep the Customer1,Order A, 1/1/2006, because in less than two years there was an order. The same for Customer 1, Order B 1/6/2006 because less than 2 years ago there was a order. however, we shouldn''t keep Customer1, Order C, 1/1/2009 because in a two year time span(before and after) there was no order. So we delete it from table.

The same logic for Customer 2, which means, first records for Customer 2,Order A,1/1/2007 will be deleted.

I don''t know how to implement this, Can anyone help me out? I would really appreciate it.

Thanks,

推荐答案

嗨莎拉,


我记得最近看到一个类似于这个回答的问题(在过去几个月内),但现在还不记得这个问题了。让我看看我是否能找到它。无论如何,我鼓励你看一看。我很确定此主题或其类似内容已在此处介绍过。


Pat
Hi sarah,

I remember seeing a question similar to this answered recently (within the past several months) but don''t remember the thread right now. Let me see if I can find it. And by all means I encourage you to look as well. I''m pretty sure this topic or something like it has been covered here previously.

Pat


@ zepphead80


感谢Pat,

我刚刚在这里创建了一个帐户。我一定会寻找这个话题。如果你找到它,请告诉我。


提前致谢,

Sarah
@zepphead80
Thanks Pat,
I just created an account here. I will definitely look for this topic. If you find it please let me know.

Thanks in advance,
Sarah


这个SQL应该这样做为了你。我建议你看一下它是如何才能获得最佳效果的。
This SQL should do it for you. I suggest you look at it to understand how it''s working for best results.
展开 | 选择 | Wrap | 行号


这篇关于日期差异记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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