Skip to content
Advertisement

Row comparison in table via SQL

I have a table which is structured like the following:

Is there a way to build a SQL query which – per each ID – looks for the Day in which Value1 OR Value2 has changed? The result I would like to achieve would be this:

In which I can keep track of those changes per ID per Day.

Edit: I’m accessing this data on a Hadoop cluster via PySpark-SQL

Advertisement

Answer

IIUC you can create a window over ID and order by day to get the desired output as

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