Skip to content
Advertisement

Oracle Analytical Function?

For the given table below, how can we find the customer whose name appears 3 times consecutively.

Desired_Output

Table Definition:

Code Tried so far

I believe we can do this by using lead/lag to get the previous and next row. Although my solution gives the desired output but i don’t think this is correct solution.

Advertisement

Answer

Your method is close. You need one more comparison:

For a more general solution, you can compare two lags:

This looks two rows back — once only by cust_id and once only for the name. If the cust_id values are the same, then all rows have the same name. You can adjust 2 to any value.

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