If you have the list of possible statuses available in a table you just need to join with a LEFT OUTER JOIN
If your list_of_status table is is:
create table list_of_status (status varchar);
insert into list_of_status values('MENANG');
insert into list_of_status values('KALAH');
insert into list_of_status values('PROSES');
insert into list_of_status values('BATAL');
insert into list_of_status values('MUNDUR');
and your data_status is
create table data_status (status varchar,kode_barang int);
insert into data_status values ('MENANG',3);
insert into data_status values ('KALAH',2);
insert into data_status values ('PROSES',3);
insert into data_status values ('MENANG',3);
SELECT
list_of_status.STATUS,
count(kode_barang) as total
FROM list_of_status LEFT OUTER JOIN data_status ON list_of_status.STATUS= data_status.STATUS
group by list_of_status.STATUS
with the expected result of
status | total
--------+-------
KALAH | 1
BATAL | 0
MENANG | 2
PROSES | 1
MUNDUR | 0
(5 rows)
If you want all the statuses in th list_of_status table PLUS any other status present in the data_status you can achieve it with a FULL_OUTER_JOIN.
e.g. if we include in the data_status a row for TEST status not available in list_of_status with
insert into data_status values ('TEST',5);
The following query returns the desired result including the TEST row
select
COALESCE(list_of_status.STATUS, data_status.STATUS) STATUS,
count(kode_barang) as total
FROM list_of_status FULL OUTER JOIN data_status ON list_of_status.STATUS= data_status.STATUS
group by COALESCE(list_of_status.STATUS, data_status.STATUS)
Result:
status | total
--------+-------
TEST | 1
MUNDUR | 0
MENANG | 2
PROSES | 1
KALAH | 1
BATAL | 0
(6 rows)
status?