mysql查询统计问题,请高手指点,查询出重复的个数,然后在重复的个数中进行其它查询

2025-03-22 19:47:12
推荐回答(1个)
回答1:

select t.* from ec_test_tbl t;


select
t.name as 姓名,
count(1) as 人数 ,
(
select count(1)
from ec_test_tbl tt where 1=1
and tt.name = t.name
and tt.sex = '男'
group by t.name
) as 男性人数
from ec_test_tbl t where 1=1
group by t.name
having count(1) > 1