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 holdings ( institution_id int, symbol varchar(32), shares int, quarter varchar(32) ); insert into holdings values (1, 'AAPL', 0, '2020_Q4'), (2, 'TSLA', 200000, '2020_Q4'), (1, 'AAPL', 100000, '2020_Q3'); select * from ( select holdings.*, lead(shares) over (partition by institution_id, symbol order by quarter desc) previous_quarter from holdings where symbol = 'AAPL' ) copmarsion where shares < coalesce(previous_quarter, 0);

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

Copy Clear