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 store ( `order` int, item varchar(30), discount varchar(30) ); INSERT INTO store VALUES (11, 'item1', 'PROMO'), (11, 'item1', 'PROMO'), (11, 'item1', 'MARKDOWN'), (11, 'item1', 'PROMO'), (11, 'item2', null), (11, 'item2', 'MARKDOWM'), (11, 'item2', null), (33, 'item1', 'PROMO'), (33, 'item1', 'PROMO'), (33, 'item1', 'PROMO'); SELECT `order`, item FROM store GROUP BY `order`, item HAVING MIN(discount) = 'PROMO' AND MAX(discount) = 'PROMO' ; select `order`, item, count(discount) from store group by `order`, item having count(discount) = count(case when discount='PROMO' then 1 end)

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

Copy Clear