Skip to content
Advertisement

SQL how can i detect if a value decrease over time?

data base structure

Hi, how can i check who are the employees whose salary has fallen ?

sql result:

I only want to fetch the name of employees whose salary has fallen

Advertisement

Answer

You can use the positional analytic function LAG() to find these rows. This is a standard SQL function that peeks at a previous row, according to a specific criteria.

For example:

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