SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
create table goods ( id int primary key, name varchar(255) ); insert into goods values (1, 'samsung 1207'), (2, 'nokia 5537'), (3, 'LG-3124'); create table prices ( id_goods int, price int, unit varchar(3), date date ); insert into prices values (1, 140, 'eur', '2020-01-01'), (1, 150, 'eur', '2021-01-01'), (2, 200, 'eur', '2019-01-01'), (2, 190, 'eur', '2020-01-01'), (2, 205, 'eur', '2021-01-01'), (3, 205, 'eur', '2021-01-01'); select g.id, g.name, count(distinct price) from goods g join prices p on g.id = p.id_goods where price in (140, 150) group by g.id, g.name having count(distinct price) = 2; select g.id, g.name, count(distinct price) from goods g join prices p on g.id = p.id_goods where price in (200, 205) group by g.id, g.name having count(distinct price) = 2;
Stuck with a problem? Got Error? Ask ChatGPT!
Copy Clear