如何查找具有多个状态为Active的Accountid的客户ID

时间:2018-04-22 07:05:48

标签: sql join group-by aggregate-functions having-clause

enter image description here

请找到我的以下查询。它是正确的还是需要修改的内容才能获得更好的优化结果。

select id,count(Accountid) from CustomerAccount
where status='Active'
group by id
having count(*)>( select min(maxxount) from(
            select id,count(accountid) as maxxount
                        from CustomerAccount
                        group by id)A)

1 个答案:

答案 0 :(得分:1)

使用此查询:

select id,count(Accountid) from CustomerAccount
where status='Active'
group by id
having count(*) >1