Anda belum menyebutkan apakah kolom type
bervariasi untuk card,service
yang diberikan pasangan. Dengan asumsi itu sama, Anda seharusnya bisa mendapatkan hasilnya dengan select
. bersarang , termasuk type
di dalam select
dan group by
.
SELECT card
,service
,CASE
WHEN type = 'v'
THEN value
ELSE perc
END AS max_result
FROM (
SELECT card
,service
,type
,MAX(date_t) AS Date_t
,MAX(value) KEEP (
DENSE_RANK FIRST ORDER BY date_t DESC
) AS value
,MAX(percentage) KEEP (
DENSE_RANK FIRST ORDER BY date_t DESC
) AS perc
FROM yourtable
GROUP BY card
,service
,type
);