SQLize Online / PHPize Online  /  SQLtest Online

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