select * from test AS o1 where (select count(1) from (select count(1) from test where name=o1.name group by age)aa)=1
please verify my account
mysql 里面有这个问题,它的子查询比较弱
不过你可以用 count(distinct 少嵌套一次,这样就没问题了
select * from test AS o1 where (select count(distinct age) from test where name=o1.name )=1
想不想时已是想,不如不想都不想。
SQL Server 里面大致没问题,加个列名就行,没有棂主的那个错误
DECLARE @test TABLE(name sysname, age varchar(10)); select * from @test AS o1 where (select count(1) from (select count(1) as 这里要个列名 from @test where name=o1.name group by age)aa)=1