Skip to content
Advertisement

Looking for the same Trader buying and selling the same product within the 3minutes

Below I’ve the example table

Basically I’m to get the same Trader buying and selling the same product within the 3minutes

Below I’ve tried this but not the correct one and working

Advertisement

Answer

Basically I’m to get the same Trader buying and selling the same product within the 3minutes

I would suggest lead(). To get the first record:

Note: This assumes that buy_sell takes on only two values, which is consistent with your sample data.

Here is a db<>fiddle. Note that it fixes the data types to be appropriate (for the time column) and renames the last column so it does not need to be escaped.

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