回答編集履歴

1 変更

sazi

sazi score 22426

2020/06/24 21:51  投稿

```SQL
select large_group, count(distinct id)
from tbl t
from G_TABLE t
where (
      select count(*) from tbl
      select count(*) from G_TABLE
      where large_group = t.large_group and id = t.id
     ) > 1
group by large_group
order by large_group
```
または
```SQL
select large_group, count(distinct id)
from tbl t
from G_TABLE t
where exists(
       select 1 from tbl
       select 1 from G_TABLE
       where large_group = t.large_group and id = t.id and small_group != t.small_group
     )
group by large_group
order by large_group
```

思考するエンジニアのためのQ&Aサイト「teratail」について詳しく知る