Articles
create table AggImage(ID,Val) as select 111,0 from dual union all select 111,2 from dual union all select 222,7 from dual union all select 222,8 from dual union all select 222,9 from dual union all select 333,1 from dual union all select 333,2 from dual union all select 444,6 from dual union all select 444,8 from dual union all select 444,9 from dual;
select ID,count(*) as cnt from AggImage group by ID order by ID;
出力結果 ID cnt --- --- 111 2 222 3 333 2 444 3
group by句のイメージは、分析関数のpartition byのイメージと似ていて、group by句で指定されたグループ化のキーごとに区切る赤線になります。

select ID,count(*) as cnt from AggImage group by ID having count(*) != 3 order by ID;
出力結果 ID cnt --- --- 111 2 333 2
having句のイメージは、where句のイメージと似ていて、group by句のイメージの赤線で区切ったグループの中で、having句での論理演算の結果が、Trueではないグループにバツを付けるグレー線になります。

|
図でイメージする
Oracle DatabaseのSQL全集 |
||