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 stats ( id bigint unsigned auto_increment primary key, product_id bigint unsigned not null, size varchar(255) not null, orders bigint unsigned default '0' not null, sales bigint unsigned default '0' not null, stocks bigint unsigned default '0' not null, warehouse_id bigint unsigned null, date date not null ); INSERT INTO stats (product_id,size,orders,sales,stocks,warehouse_id,date) VALUES (85,'45',1,1,10,1,'2023-09-01'); INSERT INTO stats (product_id,size,orders,sales,stocks,warehouse_id,date) VALUES (85,'45',1,1,8,1,'2023-09-02'); INSERT INTO stats (product_id,size,orders,sales,stocks,warehouse_id,date) VALUES (85,'45',1,1,6,1,'2023-09-03'); select product_id, size, sum(orders) as orders, sum(stocks) as stocks, warehouse_id from stats where date(`date`) >= '2023-09-01' and date(`date`) <= '2023-09-04' group by product_id, warehouse_id, size; -- я поулчаю в stoks 24 (10+8+6), а мне нужно получить значение самой поздней зааписи, те в колокне stoks должно быть 6

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

Copy Clear