I'm trying to get a full result set of all combinations from 3 tables, but its not working because I can't figure out how to tell SQL-Server 2008 what I want.
I have simplified it down to the following similar problem... I have 3 tables:
table `date_ranges`:
--------------------------------------------------------
| start_day | end_day |
| -------------------------------------------------------- |
| November, 01 2015 14:37:00 | November, 02 2015 00:00:00 |
| November, 02 2015 00:00:00 | November, 03 2015 00:00:00 |
| November, 03 2015 00:00:00 | November, 04 2015 00:00:00 |
| November, 04 2015 00:00:00 | November, 04 2015 02:00:00 |
--------------------------------------------------------
table `sites`:
----
| site |
| ---- |
| 1 |
| 2 |
| 3 |
| 4 |
----
table `all_data`:
--------------------------------------
| data_date | data_site |
| ---------------------------|---------- |
| November, 02 2015 15:35:00 | 1 |
--------------------------------------
and I want to get the following result:
-------------------------------------------------------------------------------------------------------
| data_date | data_site | start_day | end_day | site |
| ------------------------------------------------------------------------------------------------------- |
| null | null | November, 01 2015 14:37:00 | November, 02 2015 00:00:00 | 1 |
| November, 02 2015 15:35:00 | 1 | November, 02 2015 00:00:00 | November, 03 2015 00:00:00 | 1 |
| null | null | November, 03 2015 00:00:00 | November, 04 2015 00:00:00 | 1 |
| null | null | November, 04 2015 00:00:00 | November, 04 2015 02:00:00 | 1 |
| null | null | November, 01 2015 14:37:00 | November, 02 2015 00:00:00 | 2 |
| null | null | November, 02 2015 00:00:00 | November, 03 2015 00:00:00 | 2 |
| null | null | November, 03 2015 00:00:00 | November, 04 2015 00:00:00 | 2 |
| null | null | November, 04 2015 00:00:00 | November, 04 2015 02:00:00 | 2 |
| null | null | November, 01 2015 14:37:00 | November, 02 2015 00:00:00 | 3 |
| null | null | November, 02 2015 00:00:00 | November, 03 2015 00:00:00 | 3 |
| null | null | November, 03 2015 00:00:00 | November, 04 2015 00:00:00 | 3 |
| null | null | November, 04 2015 00:00:00 | November, 04 2015 02:00:00 | 3 |
| null | null | November, 01 2015 14:37:00 | November, 02 2015 00:00:00 | 4 |
| null | null | November, 02 2015 00:00:00 | November, 03 2015 00:00:00 | 4 |
| null | null | November, 03 2015 00:00:00 | November, 04 2015 00:00:00 | 4 |
| null | null | November, 04 2015 00:00:00 | November, 04 2015 02:00:00 | 4 |
-------------------------------------------------------------------------------------------------------
But instead I can only figure out how to get the following result (see fiddle here):
-------------------------------------------------------------------------------------------------------
| data_date | data_site | start_day | end_day | site |
| ------------------------------------------------------------------------------------------------------- |
| null | null | November, 01 2015 14:37:00 | November, 02 2015 00:00:00 | null |
| November, 02 2015 15:35:00 | 1 | November, 02 2015 00:00:00 | November, 03 2015 00:00:00 | 1 |
| null | null | November, 03 2015 00:00:00 | November, 04 2015 00:00:00 | null |
| null | null | November, 04 2015 00:00:00 | November, 04 2015 02:00:00 | null |
| null | null | null | null | 2 |
| null | null | null | null | 3 |
| null | null | null | null | 4 |
-------------------------------------------------------------------------------------------------------
using the following incorrect query:
select * from all_data d
full outer join date_ranges r on (r.start_day <= d.data_date and d.data_date < r.end_day)
full outer join sites s on s.site = d.data_site
A combination of CROSS JOIN and LEFT JOIN should do the trick for you.
Something like this..
SQL Fiddle
SELECT *
FROM DATE_RANGES R
CROSS JOIN SITES S
LEFT OUTER JOIN ALL_DATA D ON (R.START_DAY <= D.DATA_DATE AND D.DATA_DATE < R.END_DAY)
AND S.SITE = D.DATA_SITE
Related
I was facing this problem and spend a lot of time today. So, i thought to share it here:
I have a table where we store debitDate and we have a stored procedure where every month we set the debit date to next month in the table.
So, if its debit date is 29th Jan, 2020 -> 29th Feb, 2020 -> 29th March, 2020 - so it should go on like this. I am using DATEADD() function in the stored procedure.
But for 30th & 31st i am facing issue. It should work like below in upcoming years:
Desired Behaviour:
30th Jan, 2020 -> 29th Feb, 2020 -> 30th Mar, 2020 -> 30th Apr, 2020
30th Jan, 2021 -> 28th Feb, 2021 -> 30th Mar, 2021 -> 30th Apr, 2021
31st Jan, 2020 -> 29th Feb, 2020 -> 31st Mar, 2020 -> 30th Apr, 2020
Issue:
30th Jan, 2020 -> 29th Feb, 2020 -> 29th Mar, 2020 -> 29th Apr, 2020
30th Jan, 2021 -> 28th Feb, 2021 -> 28th Mar, 2021 -> 28th Apr, 2021
31st Jan, 2020 -> 29th Feb, 2020 -> 29th Mar, 2020 -> 29th Apr, 2020
Solution 1:
For solution i have thought i can add a new column to the table as previousDebitDate and when we update the debit date we will check, if previousDebitDate day is 30 or 31.
If true then
DATEADD(MONTH, 2, #previousDebitDate)
else
DATEADD(MONTH, 1, #debitDate)
If anyone has a better solution please feel free to post your answer.
Solution 2:
For this issue a better solution is to add debitDay as a new column to the table and save only day part (ex: 30) and calculate each month debit date on the fly.
I think Solution 2 is better! Thanks #Arvo!!!
Maybe I 've understand very well & maybe not, but here's what I think you're looking for
CREATE TABLE Data
(
Dates DATE
);
INSERT Data(Dates) VALUES
('2020-01-30');
WITH CTE AS
(
SELECT Dates,
DATEADD(Month, 1, Dates) NextMonth,
DAY(EOMONTH(DATEADD(Month, 1, Dates))) LastDay
FROM Data
UNION ALL
SELECT DATEADD(Month, 1, Dates),
DATEADD(Month, 1, NextMonth),
DAY(EOMONTH(DATEADD(Month, 1, NextMonth)))
FROM CTE
WHERE Dates <= '2021-12-31'
)
SELECT Dates, NextMonth, DATEFROMPARTS(YEAR(Dates), MONTH(NextMonth),
CASE WHEN LastDay > 30 THEN 30 ELSE LastDay END) Value
FROM CTE;
Which 'll returns:
+------------+------------+------------+
| Dates | NextMonth | Value |
+------------+------------+------------+
| 2020-01-30 | 2020-02-29 | 2020-02-29 |
| 2020-02-29 | 2020-03-29 | 2020-03-30 |
| 2020-03-29 | 2020-04-29 | 2020-04-30 |
| 2020-04-29 | 2020-05-29 | 2020-05-30 |
| 2020-05-29 | 2020-06-29 | 2020-06-30 |
| 2020-06-29 | 2020-07-29 | 2020-07-30 |
| 2020-07-29 | 2020-08-29 | 2020-08-30 |
| 2020-08-29 | 2020-09-29 | 2020-09-30 |
| 2020-09-29 | 2020-10-29 | 2020-10-30 |
| 2020-10-29 | 2020-11-29 | 2020-11-30 |
| 2020-11-29 | 2020-12-29 | 2020-12-30 |
| 2020-12-29 | 2021-01-29 | 2020-01-30 |
| 2021-01-29 | 2021-02-28 | 2021-02-28 |
| 2021-02-28 | 2021-03-28 | 2021-03-30 |
| 2021-03-28 | 2021-04-28 | 2021-04-30 |
| 2021-04-28 | 2021-05-28 | 2021-05-30 |
| 2021-05-28 | 2021-06-28 | 2021-06-30 |
| 2021-06-28 | 2021-07-28 | 2021-07-30 |
| 2021-07-28 | 2021-08-28 | 2021-08-30 |
| 2021-08-28 | 2021-09-28 | 2021-09-30 |
| 2021-09-28 | 2021-10-28 | 2021-10-30 |
| 2021-10-28 | 2021-11-28 | 2021-11-30 |
| 2021-11-28 | 2021-12-28 | 2021-12-30 |
| 2021-12-28 | 2022-01-28 | 2021-01-30 |
| 2022-01-28 | 2022-02-28 | 2022-02-28 |
+------------+------------+------------+
Much better
WITH CTE AS
(
SELECT 1 N, Dates, Dates ExpectedValue
FROM Data
UNION ALL
SELECT N+1, DATEADD(Month, 1, Dates), DATEFROMPARTS(YEAR(ExpectedValue), MONTH(DATEADD(Month, 1, ExpectedValue)),
CASE WHEN DAY(EOMONTH(DATEADD(Month, 1, ExpectedValue))) > 30 THEN 30
ELSE DAY(EOMONTH(DATEADD(Month, 1, ExpectedValue)))
END)
FROM CTE
WHERE N < 15
)
SELECT *
FROM CTE
ORDER BY N;
Returns:
+----+------------+---------------+
| N | Dates | ExpectedValue |
+----+------------+---------------+
| 1 | 2020-01-30 | 2020-01-30 |
| 2 | 2020-02-29 | 2020-02-29 |
| 3 | 2020-03-29 | 2020-03-30 |
| 4 | 2020-04-29 | 2020-04-30 |
| 5 | 2020-05-29 | 2020-05-30 |
| 6 | 2020-06-29 | 2020-06-30 |
| 7 | 2020-07-29 | 2020-07-30 |
| 8 | 2020-08-29 | 2020-08-30 |
| 9 | 2020-09-29 | 2020-09-30 |
| 10 | 2020-10-29 | 2020-10-30 |
| 11 | 2020-11-29 | 2020-11-30 |
| 12 | 2020-12-29 | 2020-12-30 |
| 13 | 2021-01-29 | 2020-01-30 |
| 14 | 2021-02-28 | 2020-02-29 |
| 15 | 2021-03-28 | 2020-03-30 |
+----+------------+---------------+
Here is a db<>fiddle
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have a table with promo sales, but some promos last a different amount of time.
+---------+-------------+---------+----------+------------+-----+
| year_id | week_number | good_id | store_id | promo_name | qty |
+---------+-------------+---------+----------+------------+-----+
| 2019 | 41 | 22197 | 64 | October | 10 |
+---------+-------------+---------+----------+------------+-----+
| 2019 | 42 | 22197 | 64 | October | 2 |
+---------+-------------+---------+----------+------------+-----+
| 2019 | 43 | 22197 | 64 | October | 54 |
+---------+-------------+---------+----------+------------+-----+
| 2019 | 44 | 22197 | 64 | October | 3 |
+---------+-------------+---------+----------+------------+-----+
| 2019 | 41 | 22197 | 64 | Flash | 13 |
+---------+-------------+---------+----------+------------+-----+
| 2019 | 42 | 22197 | 64 | Flash | 56 |
+---------+-------------+---------+----------+------------+-----+
| 2019 | 42 | 22197 | 64 | New | 41 |
+---------+-------------+---------+----------+------------+-----+
| 2019 | 43 | 22197 | 64 | New | 4 |
+---------+-------------+---------+----------+------------+-----+
I would like to find for each pair of good-store all such cases where shorter promos go into longer ones and change their name, for example:
+---------+-------------+---------+----------+------------+-----+
| year_id | week_number | good_id | store_id | promo_name | qty |
+---------+-------------+---------+----------+------------+-----+
| 2019 | 41 | 22197 | 64 | October | 10 |
+---------+-------------+---------+----------+------------+-----+
| 2019 | 42 | 22197 | 64 | October | 2 |
+---------+-------------+---------+----------+------------+-----+
| 2019 | 43 | 22197 | 64 | October | 54 |
+---------+-------------+---------+----------+------------+-----+
| 2019 | 44 | 22197 | 64 | October | 3 |
+---------+-------------+---------+----------+------------+-----+
| 2019 | 41 | 22197 | 64 | October | 13 |
+---------+-------------+---------+----------+------------+-----+
| 2019 | 42 | 22197 | 64 | October | 56 |
+---------+-------------+---------+----------+------------+-----+
| 2019 | 42 | 22197 | 64 | October | 41 |
+---------+-------------+---------+----------+------------+-----+
| 2019 | 43 | 22197 | 64 | October | 4 |
+---------+-------------+---------+----------+------------+-----+
For the first value of promo_name when sorted by year & week for the same good_id & store_id
Then the FIRST_VALUE window function would be my pick.
SELECT year_id, week_number, good_id, store_id,
FIRST_VALUE(promo_name) OVER (PARTITION BY good_id, store_id ORDER BY year_id, week_number) AS promo_name,
qty
FROM PromoSales ps
ORDER BY 1, 2, 3, 4
To use it in an update
WITH CTE AS
(
SELECT
promo_name,
FIRST_VALUE(promo_name) OVER (PARTITION BY good_id, store_id ORDER BY year_id, week_number) AS original_promo_name
FROM PromoSales
)
UPDATE CTE
SET promo_name = original_promo_name
WHERE promo_name != original_promo_name
AND original_promo_name IS NOT NULL;
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I've table User_LogTime like this:
________________________________
| Date | User ID | Name |
| 1 Jan 2019 | 00001 | Andy |
| 1 Jan 2019 | 00002 | Benn |
| 2 Jan 2019 | 00001 | Andy |
| 3 Jan 2019 | 00001 | Andy |
| 4 Jan 2019 | 00001 | Andy |
| 4 Jan 2019 | 00002 | Benn |
| 4 Jan 2019 | 00003 | Jack |
--------------------------------
I want make query result like this:
________________________________
| Date | User ID | Name |
| 1 Jan 2019 | 00001 | Andy |
| 2 Jan 2019 | 00001 | Andy |
| 3 Jan 2019 | 00001 | Andy |
| 4 Jan 2019 | 00001 | Andy |
| 1 Jan 2019 | 00002 | Benn |
| 2 Jan 2019 | null | null |
| 3 Jan 2019 | null | null |
| 4 Jan 2019 | 00002 | Benn |
| 1 Jan 2019 | null | null |
| 2 Jan 2019 | null | null |
| 3 Jan 2019 | null | null |
| 4 Jan 2019 | 00003 | Jack |
---------------------------------
Date period set from query, result group by User ID and sort by Date.
What query to get that result?
One option would be to join with a calendar table which contains all dates you expect in the output. I also assume that you have a user table somewhere, containing all user IDs. For example:
WITH cal AS (
SELECT '2019-01-01' AS dt UNION ALL
SELECT '2019-01-02' UNION ALL
SELECT '2019-01-03' UNION ALL
SELECT '2019-01-04'
)
SELECT c.dt, u.user_id, ult.name
FROM cal c
CROSS JOIN users u
LEFT JOIN User_LogTime ult
ON c.dt = ult.Date AND u.user_id = ult.user_id
ORDER BY
u.user_id,
c.dt;
I have a table to track the Student details and there is another table to track the performance of the student.
+==========================================+
| ID | Department | Date |
+==========================================+
| 001 | English | Jan 3 2017 |
| 001 | English | Feb 24 2017 |
| 001 | Science | Mar 1 2017 |
| 001 | Maths | Mar 2 2017 |
| 001 | Maths | Mar 21 2017 |
| 001 | Maths | Apr 2 2017 |
| 001 | English | Apr 7 2017 |
| 002 | Maths | Feb 1 2017 |
| 002 | Maths | Apr 7 2017 |
| 003 | Maths | Apr 3 2017 |
| 003 | Maths | Apr 7 2017 |
| 004 | Science | Feb 1 2017 |
| 004 | Science | Mar 1 2017 |
| 004 | Maths | Apr 7 2017 |
| 004 | English | Apr 9 2017 |
+==========================================+
Performance table:
+===========================================================================+
| ID | Department | Best score| Avg score | Date |
+===========================================================================+
| 001 | English | 98 | 85 | Jan 30 2017 |
| 001 | English | 89 | 80.2 | Apr 14 2017 |
| 001 | Science | 75 | 79.8 | May 1 2017 |
| 001 | Maths | 88 | 80.2 | Jan 12 2017 |
| 001 | Maths | 79 | 75.6 | Feb 21 2017 |
| 001 | Maths | 90 | 80.5 | Jan 20 2017 |
| 001 | English | 80 | 79.3 | Mar 27 2017 |
| 002 | Maths | 90 | 78.4 | Mar 31 2017 |
| 002 | Maths | 85 | 80.2 | May 7 2017 |
| 003 | Maths | 75 | 79.1 | Apr 30 2017 |
| 003 | Maths | 80 | 80.0 | Feb 7 2017 |
| 004 | Science | 60 | 70.3 | May 1 2017 |
| 004 | Science | 72 | 69.9 | Mar 10 2017 |
| 004 | Maths | 70 | 66.8 | Jan 17 2017 |
| 004 | English | 65 | 65.0 | Mar 29 2017 |
+===========================================================================+
I want to get the most recent performance and average score of the student whenever a department change happens in the student table. Considering student 001, the student's dept changes are
| 001 | English | Jan 3 2017 |
| 001 | Science | Mar 1 2017 |
| 001 | Maths | Apr 2 2017 |
For,
Jan 3 2017, There is no date that is less than the date in the Performance table.
Mar 1 2017, The most recent record in performance table is of date Feb 21 2017
Apr 2 2017, The most recent record in performance table is of date Mar 27 2017
Please help me in doing it.
Take a little pain to explain clearly if my script is wrong
Hope the output that you have explain is correct.Becasue i hv lil doubts about the output.
Most importantly hope you have posted exactly same table structure .
Because of your table structure,lil more window function is use than expected,which may hamper your performance.
It is all together very different and important discussion about your real requirement and what should be table structure and how it should be populated.
Try this script with various sample data and let me know,
declare #StudentDetails table(ID varchar(20)
,Department varchar(20),Dates Date)
insert into #StudentDetails VALUES
('001','English','Jan 3 2017 ')
,('001','English','Feb 24 2017')
,('001','Science','Mar 1 2017 ')
,('001','Maths','Mar 2 2017 ')
,('001','Maths','Mar 21 2017')
,('001','Maths','Apr 2 2017 ')
,('001','English','Apr 7 2017 ')
,('002','Maths','Feb 1 2017 ')
,('002','Maths','Apr 7 2017 ')
,('003','Maths','Apr 3 2017 ')
,('003','Maths','Apr 7 2017 ')
,('004','Science','Feb 1 2017 ')
,('004','Science','Mar 1 2017 ')
,('004','Maths','Apr 7 2017 ')
,('004','English','Apr 9 2017 ')
--select * from #StudentDetails
declare #Performance table( ID varchar(20)
,Department varchar(20),Bestscore float,Avgscore float,PDate date)
insert into #Performance VALUES
('001','English',98,85 ,'Jan 30 2017')
,('001','English',89,80.2 ,'Apr 14 2017')
,('001','Science',75,79.8 ,'May 1 2017 ')
,('001','Maths',88,80.2 ,'Jan 12 2017')
,('001','Maths',79,75.6 ,'Feb 21 2017')
,('001','Maths',90,80.5 ,'Jan 20 2017')
,('001','English',80,79.3 ,'Mar 27 2017')
,('002','Maths',90,78.4 ,'Mar 31 2017')
,('002','Maths',85,80.2 ,'May 7 2017 ')
,('003','Maths',75,79.1 ,'Apr 30 2017')
,('003','Maths',80,80.0 ,'Feb 7 2017 ')
,('004','Science',60,70.3 ,'May 1 2017 ')
,('004','Science',72,69.9 ,'Mar 10 2017')
,('004','Maths',70,66.8 ,'Jan 17 2017')
,('004','English',65,65.0 ,'Mar 29 2017')
--select * from #Performance
--declare #SID varchar(20)='001'
;with CTE as
(
select *
,ROW_NUMBER()over(partition by id order by Dates,Department) rn
from #StudentDetails
--where id=#SID
)
,CTE3 AS(
select c.id, c.Department,c.dates,c.rn,1 rn3
from cte c
where rn=1
union ALL
select c.id, c.Department,c.dates,c.rn
,case when c.Department=c3.Department and c.dates>c3.dates
then cast(c3.rn3 as int)
else cast(c3.rn3+1 as int) end
from cte c
inner join cte3 c3
on c.id=c3.id
where c.rn=c3.rn+1
and c.rn<=7
)
,cte4 AS(
select *,0 rn1 from cte3 where rn=1
union ALL
select * from
(
select * ,ROW_NUMBER()over(PARTITION by id,rn3 order by dates desc) rn1
from cte3
where rn3>1
)t4 where t4.rn1=1
)
select c.id,c.department,c.dates,fn.Avgscore AVGScroe,fn.pdate RecentPDate
from cte4 c
OUTER apply(
select * from
(select p.*,ROW_NUMBER()over( order by pdate desc)rn2
from #Performance P
where c.id=p.id and p.pDate<c.dates)t4
where rn2=1 )fn
order by c.id
Could you try this...
SELECT S.ID,S.DATE,MAX(P.AVG_SCORE),MAX(P.BEST_SCORE)
FROM STUDENT S, PERFORMANCE P
WHERE P.DATE < S.DATE AND P.ID = S.ID
GROUP BY S.ID,S.DATE
Thanks..
I have one table Fee_Payable_to_Students. To organize values of this table I have coded as
create PROC [dbo].[Fee_Fee_Demand](#S_Adm_No NVARCHAR(50))
AS
BEGIN
SELECT cls_SecId, S_Adm_No, Installment,
SUM(Amount) AS Amount, CASE
WHEN Installment = 'Quarter-1 (April, May & June)' THEN 'Apr 15, 2017'
WHEN Installment = 'Quarter-2 (July, August & September)' THEN 'Jul 15, 2017'
WHEN Installment = 'Quarter-3 (October, November & December)' THEN 'Oct 15, 2017'
WHEN Installment = 'Quarter-4 (January, February & March)' THEN 'Jan 15, 2018' END AS Payable_Date
FROM ( SELECT cls_SecId, S_Adm_No,
Apr + May + Jun AS [Quarter-1 (April, May & June)],
Jul + Aug + Sep AS [Quarter-2 (July, August & September)],
Oct + Nov + Dec AS [Quarter-3 (October, November & December)],
Jan + Feb + Mar AS [Quarter-4 (January, February & March)]
FROM Fee_Payable_to_Students where S_Adm_No=#S_Adm_No) AS Pvt UNPIVOT
(Amount FOR Installment IN
([Quarter-1 (April, May & June)],
[Quarter-2 (July, August & September)],
[Quarter-3 (October, November & December)],
[Quarter-4 (January, February & March)])) AS unPvt
GROUP BY cls_SecId, S_Adm_No, Installment
end
the value displays like
Installment | Amount | Payable_Date
Quarter-1 (April, May & June) | | Apr 15, 2017
Quarter-2 (July, August & September) | | Jul 15, 2017
Quarter-3 (October, November & December)| | Oct 15, 2017
Quarter-4 (January, February & March) | | Jan 15, 2018
Besides this One more table is there in name of Fee_Receipt.
Now My question is if Fee_receipt has values like
S_Amn_No |Fhead | Apr | May |Jun | Jul | Aug | Sep | Oct | Nov | Dec | Jan | Feb | Mar
1001 |1 | 100 | 100 |100 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0
1001 |2 | 100 | 100 |100 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0
1001 |3 | 100 | 100 |100 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0
Then the value should show like
Installment | Amount | Status | Payable_Date
Quarter-1 (April, May & June) | assumed(900) | FeePaid | Apr 15, 2017
Quarter-2 (July, August & September) | | Pending | Jul 15, 2017
Quarter-3 (October, November & December)| | Pending | Oct 15, 2017
Quarter-4 (January, February & March) | | Pending | Jan 15, 2018
if Fee_receipt has value like
S_Amn_No |Fhead | Apr | May |Jun | Jul | Aug | Sep | Oct | Nov | Dec | Jan | Feb | Mar
1001 |1 | 100 | 100 |100 | 100 | 100 |100 | 0 | 0 | 0 | 0 | 0 | 0
1001 |2 | 100 | 100 |100 | 100 | 100 | 0 | 0 | 0 | 0 | 0 | 0 | 0
1001 |3 | 100 | 100 |100 | 100 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0
Then the value should show like
Installment | Amount | Status | Payable_Date
Quarter-1 (April, May & June) | assumed(900) | Paid | Apr 15, 2017
Quarter-2 (July, August & September) | assumed(1200) | 600 | Jul 15, 2017
Quarter-3 (October, November & December)| assumed(1200) | 1200 | Oct 15, 2017
Quarter-4 (January, February & March) | assumed(1200) | 1200 | Jan 15, 2018
like wise for two more quarter.