Skip to content
Advertisement

How can I join a table to itself to get the values needed?

So I have a table that I’m trying to join to and I’m not quite getting everything I need. So I have a table that looks like this. I want to see if there is a way to join this table to itself to get the rest, so I see that when I see the code ‘0013’ then I should be getting a code of ‘0013’ code_type of ‘9_prcdr’ and med_code_ID of 74717. I’ve tried to join this to itself, but I’m either not getting enough rows or getting too many. I’ve looked online and I see there is a function I could try which is lead or lag, but I don’t have too much experience with it. Could you help? Thank you!

This is what it should look like.

And my attempt was this :

Advertisement

Answer

I suspect that you can use window functions:

This assumes that there a given prcdr_cd correspond to a unique tuple of values of code, code_type and med_code_ID.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement