sqlにおけるwhere,groupby,havingの使用解析
2998 ワード
group by “ ” 。 : 。
having (group by) ,
where
where , having , HAVING 。
having
having ,
having select 。 , oracle
where 、group by 、having , :
where ;
group by ; group by ;
having
ex: . 1000000 。
SELECT region, SUM(population), SUM(area)
FROM bbc
GROUP BY region
HAVING SUM(area)>1000000
, where 1000000 , 。(where )
,HAVING
1、 20, 2
select COUNT
(age)
as
'>20 '
,classid
from Table1
where sex=' '
group by classid
having COUNT(age)>2
*sc( ) 、SNO( )、PNO( )、GRADE( )
2、
90
select sno,pno,grade
from sc
where grade>=90;
3、
90
//
, where
select sno,
count
(*)
from sc
where grade>=90
group by sno;
4、
90 90 。
// , where , having 。 90 ,
select sno,
count
(*)
from sc
where grade>=90
group by sno
having
count
(*)>=2;
5、 90 95
// , 95 , , having 90
select sno,avg(grade)
from sc
where SNO IN (SELECT SNO FROM SC WHERE GRADE>=95 AND PNO=
'YW'
)
group by sno
having avg(grade)>=90;
6、
3
//having , 3 , , 。
select sno,avg(grade)
from sc
group by sno
having avg(grade) > (select avg(grade) from sc where sno=3);