My data in table
ARREARS_IN_DAYS |
BALANCE_DATE |
ACCT_ID |
0 |
11/30/2021 |
11002140008598 |
0 |
12/31/2021 |
11002140008598 |
8 |
1/31/2022 |
11002140008598 |
5 |
2/28/2022 |
11002140008598 |
8 |
3/31/2022 |
11002140008598 |
6 |
4/29/2022 |
11002140008598 |
8 |
5/31/2022 |
11002140008598 |
7 |
6/30/2022 |
11002140008598 |
Script
WITH cte_month AS
(SELECT row_number() OVER(PARTITION BY to_char(r.balance_date, 'Month'), to_char(r.balance_date, 'Year') ORDER BY balance_date DESC) row_num,
arrears_in_days,
balance_date,
acct_id
FROM report r
where r.acct_id = '11002140008598'
and (to_char(r.balance_date, 'D')) not in (6, 7))
SELECT * FROM
(
SELECT arrears_in_days, balance_date
FROM cte_month
WHERE row_num = 1
)
PIVOT
(
count(arrears_in_days)
FOR balance_date IN ('30.11.2021','31.12.2021','31.01.2022','28.02.2022','31.03.2022','29.04.2022','31.05.2022','30.06.2022')
)
Here I want show value from table. But the result I got it different:
'30.11.2021' |
'31.12.2021' |
'31.01.2022' |
'28.02.2022' |
'31.03.2022' |
'29.04.2022' |
'31.05.2022' |
'30.06.2022' |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
Here I show each value by date. My requirement result in below:
'30.11.2021' |
'31.12.2021' |
'31.01.2022' |
'28.02.2022' |
'31.03.2022' |
'29.04.2022' |
'31.05.2022' |
'30.06.2022' |
0 |
0 |
8 |
5 |
8 |
6 |
8 |
7 |