[英]Check value exist in previous month in SQL
I have two table XYZ and ABC 我有两个表XYZ和ABC
create table #abc(id int, value int, dates date)
create table #xyz(id int, value int, dates date)
insert into #xyz values(1,10,'2017/02/01')
Insert into #xyz values(2,10,'2017/05/01')
Insert into #abc values(1,10,'2017/01/01')
Insert into #abc values(1,20,'2017/02/01')
Insert into #abc values(2,4,'2017/01/01')
Insert into #abc values(2,5,'2017/04/01')
XYZ
ID Value Dates
1 10 2017/02/01
2 10 2017/05/01
ABC
ID Values Dates ExpectedResult
1 10 2017/01/01 20
1 20 2017/02/01 0
2 4 2017/01/01 0
2 5 2017/04/01 15
i want to check if table ABC having (Month - 1 ) value comparing with table XYZ. 我想检查表ABC是否具有与表XYZ相比(月-1)的值。 Uniqueness of table is identified by ID and Date .
表的唯一性由ID和Date标识。 For eg-> Table XYZ id-1 is having date 2017/02/01 ie February data and my ABC table ID-1 is having 2017/01/01 ie January data then XYZ value + ABC value ie 20 is the expected result.
对于例如->表XYZ id-1具有日期2017/02/01,即2月数据,而我的ABC表ID-1具有2017/01/01,即1月数据,则XYZ值+ ABC值,即20是预期结果。
Could you please tell me how do we compare month in this scenario. 您能告诉我在这种情况下我们如何比较月份。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.