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 t (user_id int, value_id int, amount int, created_at date, updated_at date); insert into t values (1, 22, 1, '2022-02-02', '2022-02-02'), (1, 23, 2, '2022-02-02', '2022-02-02'), (1, 23, 1, '2022-02-02', '2022-02-02'), (2, 22, 3, '2022-02-02', '2022-02-02'), (2, 22, 4, '2022-02-02', '2022-02-02'), (2, 22, 1, '2022-02-02', '2022-02-02'), (3, 24, 3, '2022-02-02', '2022-02-02'), (3, 24, 3, '2022-02-02', '2022-02-02'); select user_id from t where value_id = 22 group by user_id having count(*) >= 1 intersect select user_id from t where value_id = 23 group by user_id having count(*) >= 2; with count_values as ( select user_id, value_id, count(*) cnt from t group by user_id, value_id ) select user_id from count_values where value_id = 22 and cnt > 0 intersect select user_id from count_values where value_id = 23 and cnt > 1

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

Copy Clear