资源描述:
《对Oracle中分组函数的一点点理解》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、GroupbyissometimesusedtousethefollowinggroupingfunctionsCount(AVG)(max)();//generalapplicationinthedigita1.Min();sum()Ifthegroupingfunctionisusedintheprogram,therearetwothingsthatcanbeused:1.Groupbyispresentintheprogramandthegroupingconditionsareformulatedsothatthegroup
2、ingconditionscanbequeriedtogether2.Ifyoudonotusegroupby,youcanonlyusethegroupingfunctionaloneSo:selectdeptno,countfromEMP(empno);//error:notasinglegroupfunctionChange:select,deptno,count(empno),from,EMP,group,by,deptno;Selectdeptno,ename,count(empno)fromEMPgroupbydeptno
3、;//error:notagroupbyexpressionThesummaryisthatthegroup,by,andgroupfunctionsgivetheconceptofthefieldgroup,andinthatcasethegroupbyismodifiedFieldsandfieldsthataremodifiedbygroupfunctionsaregroupfields,andtheprecedingisnotagroupfield,andofcoursethereisanerrorWhere,group,by
4、,having,order,by,wghoIwalkRequiredtoshowanaveragewagegreaterthan2000ofthedepartmentnumberandaveragewage・Select,deptno,AVG(SAL)FromEMPWhereAVG(SAL)>2000Min();sum()Ifthegroupingfunctionisusedintheprogram,therearetwothingsthatcanbeused:1.Groupbyispresentintheprogramandtheg
5、roupingconditionsareformulatedsothatthegroupingconditionscanbequeriedtogether2.Ifyoudonotusegroupby,youcanonlyusethegroupingfunctionaloneSo:selectdeptno,countfromEMP(empno);//error:notasinglegroupfunctionChange:select,deptno,count(empno),from,EMP,group,by,deptno;Selectd
6、eptno,ename,count(empno)fromEMPgroupbydeptno;//error:notagroupbyexpressionThesummaryisthatthegroup,by,andgroupfunctionsgivetheconceptofthefieldgroup,andinthatcasethegroupbyismodifiedFieldsandfieldsthataremodifiedbygroupfunctionsaregroupfields,andtheprecedingisnotagroupf
7、ield,andofcoursethereisanerrorWhere,group,by,having,order,by,wghoIwalkRequiredtoshowanaveragewagegreaterthan2000ofthedepartmentnumberandaveragewage・Select,deptno,AVG(SAL)FromEMPWhereAVG(SAL)>2000Groupbydeptno;//thethirdlineerror:itdoesnotallowtheuseofpacketfunctionGroup
8、ingfunctionscanonlybeusedingroupsandarenotallowedtooccurinwherestatements,andwecanonlyusepacketfilteringSelect