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( date date, type text, price int ); insert into t values ("2020-01-01", "laptop", "210"), ("2020-01-01", "pc", "100"), ("2020-01-02", "laptop", "150"), ("2020-01-02", "pc", "200"), ("2020-01-03", "laptop", "150"), ("2021-01-01", "pc", "110"), ("2021-01-01", "laptop", "220"), ("2021-01-02", "pc", "210"), ("2021-01-02", "laptop", "200"), ("2021-01-03", "pc", "26"); select date, abs(sum-first_month_value)/2 from (select sum(price) as sum, count(date) as count, date, first_value(sum(price)) over() as first_month_value from t group by date order by date) as t;

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

Copy Clear