with t1 as (
SELECT
hospital_ids AS hospital_id,
operation_type_id AS bd_id,
row_number() over(PARTITION by hospital_ids order by id desc) as rn
FROM
tb_hospital_bd_log
WHERE
operation_type = 2
)
SELECT *
from t1 WHERE rn = 1