I have the following dataset:
ID Amount 1 50 2 6 3 7 3 50 4 60 4 30 5 40 5 20
I only want to keep IDs with multiple entries that have at least one amount greater than, or equal to, 50. The final result would look like this:
ID Amount 3 7 3 50 4 60 4 30
How would I go about doing this?
Advertisement
Answer
You can use windows function max
as follows:
select * from (select t.*, max(amount) over (partition by id) as max_ from your_table t) t where max_ >= 50