Hello I have a Postgresql code that return more one value in subquery following below. that i want to return year, month, region, name, total incoming (this has conditional where), and total sales (this has conditional where which has different conditional with total incoming). Sure my logic is wrong. but anybody help me to solve this case?
select
distinct
x.year_s_date Tahun,
x.month_s_date Bulan,
y.regionalname Region,
y.namarm nama_rm,
(select
distinct sum(s_totalfinancing) incoming
from staging.main_eform_kpm_final a
inner join (
select *
from landing.confins_dwh_rmkmb
where enddate > '2020-01-01'
) b on a.branch_code = b.branchid
where a.db_source is not null
group by a.year_s_date, a.month_s_date, b.regionalname, b.namarm
),
(
select distinct sum(s_totalfinancing) sales
from staging.main_eform_kpm_final a
inner join (
select *
from landing.confins_dwh_rmkmb
where enddate > '2020-01-01'
) b on a.branch_code = b.branchid
where a.db_source is not null and a.db_source_2 is not null and lineage ='1'
group by a.year_s_date, a.month_s_date, b.regionalname, b.namarm
)
from staging.main_eform_kpm_final x
inner join (
select *
from landing.confins_dwh_rmkmb
where enddate > '2020-01-01'
) y on x.branch_code = y.branchid
limit 1
in your subquery