3,492
社区成员
发帖
与我相关
我的任务
分享
select * from person where name in (
select Name from person where sex ='女' and age=28
)
SELECT t.*
FROM ( -- 先统计出一人以上的年龄段
SELECT age
FROM person
WHERE sex = '女'
GROUP BY age
HAVING COUNT(*) > 1
) s
JOIN person t
ON s.age = t.age -- 再用年龄段过滤明细
WHERE t.sex = '女'
ORDER BY t.Age , t.CardNo
with ag as (select t.age,count(t.CardNo) as count_n from person t where t.sex='女' group by t.age having count(t.CardNo)>1)
select * from person u where u.sex='女' and exists (select 1 from ag where ag.age=u.age);
select t.CardNo, t.Name, t.age ,t.sex ,count(t.CardNo) as count_num from person t
where t.sex = '女'
Group by t.CardNo, t.Name, t.age ,t.sex
having count(t.CardNo) > 1