34,590
社区成员
发帖
与我相关
我的任务
分享
select
*
from
tb
where
username in(select username from tb group by username having count(1)=2)
and
product_id in('363','365')
SELECT * FROM TB T
WHERE EXISTS(SELECT 1 FROM TB WHERE username=T.username AND product_id=363) AND
EXISTS(SELECT 1 FROM TB WHERE username=T.username AND product_id=365)
with t1 as
(
select Username, product_id
from tablename
where product_id = 363
group by Username, product_id
),
t2 as
(
select Username, product_id
from tablename
where product_id = 365
group by Username, product_id
)
select Username
from t1
where Username in
(select Username
from t2)