Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize | PHPize | SQLtest

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

A A A
Login    Share code      Blog   FAQ
Copy Format Clear
create table t ("data" date, "name" text, dep text, salary int); insert into t values ('2023-03-31', 'Иванов Иван Иванович', 'Департамент 1', 40000), ('2023-03-31', 'Сидоров Валерий Валериевич', 'Департамент 1', 70000), ('2023-04-30', 'Иванов Иван Иванович', 'Департамент 1', 50000), ('2023-04-30', 'Сидоров Валерий Валериевич', 'Департамент 1', 75000); select "data", "name", dep, salary, prev_salary, coalesce(salary - prev_salary, 0) as diff from ( select *, lag(salary) over (partition by "name" order by "data") as prev_salary from t )foo

Stuck with a problem? Got Error? Ask AI support!

Copy Clear