Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize Online / PHPize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear
CREATE TABLE Goods(Store VARCHAR(255), Food VARCHAR(255), Amount INT); INSERT INTO Goods(Store, Food, Amount) VALUES ('Store 1', 'potato', 50), ('Store 5', 'potato', 150), ('Store 12', 'potato', 300), ('Store 1', 'tomato', 220), ('Store 5', 'tomato', 180), ('Store 12', 'tomato', 60), ('Store 1', 'cucumber', 500), ('Store 5', 'cucumber', 10), ('Store 12', 'cucumber', 90); SELECT Store, SUM(CASE WHEN Food = 'potato' THEN Amount END) "potatos", SUM(CASE WHEN Food = 'tomato' THEN Amount END) "tomato", SUM(CASE WHEN Food = 'cucumber' THEN Amount END) "cucumbers" FROM Goods GROUP BY Store;

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

Copy Clear