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 datas ( `type` VARCHAR(10) NOT NULL, `number` VARCHAR(10) NOT NULL, `quantity` INT NOT NULL, `date_status` TINYINT NOT NULL ); INSERT INTO datas (`type`,`number`,`quantity`,`date_status`) VALUES ('sup','555',280,1), ('sup','000',245,1), ('sup','777',235,1), ('sup','888',235,1), ('bo' ,'000', 40,1), ('bo' ,'777', 30,1), ('bo' ,'888', 25,1), ('bo' ,'555', 10,1); SELECT type, number, quantity count FROM datas d JOIN ( SELECT number, SUM(quantity) total FROM datas WHERE date_status = 1 GROUP BY number ) t USING (number) WHERE date_status = 1 ORDER BY total DESC

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

Copy Clear