SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
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 ChatGPT!
Copy Clear