No ha mencionado si la columna type
varía para una determinada card,service
par. Suponiendo que sea lo mismo, debería poder obtener el resultado con un select
anidado , incluido type
en el interior select
y 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
);