所以我有一个它的状态可以改变的记录。初始状态为申请、已提交、已完成交易最终的夫妇状态并不总是相同的,但主要的重要性是已完成交易。我正在尝试创建一个查询,以确定记录在日期参数StartDate和EndDate期间是否处于已完成交易状态。该记录有一个已创建和已修改的列。修改自动设置为创建日期,直到添加另一个状态。
例如:
Loan Status Created Modified IsCurrent
1 Application 2015-01-01 2015-01-01 true触发下一次状态更新2015年2月1日*
Loan Status Created Modified IsCurrent
1 Application 2015-01-01 2015-02-01 false
1 Committed 2015-02-01 2015-02-01 true我可以编写查询来查找在日期参数期间创建或修改的已完成交易的记录,以及在开始日期参数之前创建的当前记录。我在查询以下记录时遇到问题:创建日期在开始日期之前,完成交易后的下一个状态添加在结束日期参数之后。
例如
StartDate = 2015-01-01
EndDate = 2015-04-01
Loan Status Created Modified IsCurrent
1 Application 2014-10-01 2014-11-01 false
1 Committed 2014-11-01 2014-11-01 false
1 Closed Deal 2014-12-01 2015-05-01 false
1 Paid Off 2015-05-01 2015-05-01 true我的当前查询
select * from LoanStatusHistories
join LoanStatus on LoanStatusHistories.LoanStatus_Id = Loanstatus.Id
where LoanStatus.Value = 'Closed Deal' and
((LoanStatusHistories.Created >= '2015-01-01' and
LoanStatusHistories.Modified <= '2015-04-01' ) or
IsCurrent = 1)发布于 2015-03-26 22:31:46
我假设状态更改总是会导致创建一个新的LoanStatus,对吗?然后,您只需关注已创建的字段。我还假设"IsCurrent“的值与您的用例无关。
select * from LoanStatusHistories
join LoanStatus on LoanStatusHistories.LoanStatus_Id = Loanstatus.Id
where LoanStatus.Value = 'Closed Deal' and
((LoanStatusHistories.Created >= '2015-01-01' and
LoanStatusHistories.Created<= '2015-04-01' ))如果您想要检查上述两种状态:
LoanStatus.Value in ('Closed Deal', 'Committed')编辑: LoanStatusHistories表中是否也有Value字段?如果是,请使用此命令。否则,您将无法获取已提交/已关闭并稍后设置为其他状态的交易。这有可能吗?“已提交”后的“已支付”?
https://stackoverflow.com/questions/29280886
复制相似问题