|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
不可否认,MySQL也是一个很好的关系型数据库,或许在技术上它与其他领先的关系数据库相差并不大,或不具有劣势。但是,对于一些企业环境来说,MySQL显然不具有优势。oracle|参考|参考手册|函数Oracle从8.1.6入手下手供应剖析函数,剖析函数用于盘算基于组的某种聚合值,它和聚合函数的分歧的地方是关于每一个组前往多行,而聚合函数关于每一个组只前往一行。上面例子中利用的表来自Oracle自带的HR用户下的表,假如没有安装该用户,能够在SYS用户下运转$ORACLE_HOME/demo/schema/human_resources/hr_main.sql来创立。多数几个例子必要会见SH用户下的表,假如没有安装该用户,能够在SYS用户下运转$ORACLE_HOME/demo/schema/sales_history/sh_main.sql来创立。假如未指明缺省是在HR用户下运转例子。开窗函数的的了解:开窗函数指定了剖析函数事情的数据窗口巨细,这个数据窗口巨细大概会跟着行的变更而变更,举比方下:over(orderbysalary)依照salary排序举行累计,orderby是个默许的开窗函数over(partitionbydeptno)依照部门分区over(orderbysalaryrangebetween50precedingand150following)每行对应的数据窗口是之前行幅度值不凌驾50,以后行幅度值不凌驾150over(orderbysalaryrowsbetween50precedingand150following)每行对应的数据窗口是之前50行,以后150行over(orderbysalaryrowsbetweenunboundedprecedingandunboundedfollowing)每行对应的数据窗口是从第一行到最初一行,等效:over(orderbysalaryrangebetweenunboundedprecedingandunboundedfollowing)次要参考材料:《expertone-on-one》TomKyte《Oracle9iSQLReference》第6章AVG功效形貌:用于盘算一个组和数据窗口内表达式的均匀值。SAMPLE:上面的例子中列c_mavg盘算员工表中每一个员工的均匀薪水呈报,该均匀值由以后员工和与之具有不异司理的前一个和后一个三者的均匀数得来;SELECTmanager_id,last_name,hire_date,salary,AVG(salary)OVER(PARTITIONBYmanager_idORDERBYhire_dateROWSBETWEEN1PRECEDINGAND1FOLLOWING)ASc_mavgFROMemployees;MANAGER_IDLAST_NAMEHIRE_DATESALARYC_MAVG----------------------------------------------------------------100Kochhar21-SEP-891700017000100DeHaan13-JAN-931700015000100Raphaely07-DEC-941100011966.6667100Kaufling01-MAY-95790010633.3333100Hartstein17-FEB-96130009633.33333100Weiss18-JUL-96800011666.6667100Russell01-OCT-961400011833.3333...CORR功效形貌:前往一对表达式的相干系数,它是以下的缩写:COVAR_POP(expr1,expr2)/STDDEV_POP(expr1)*STDDEV_POP(expr2))从统计上讲,相干性是变量之间联系关系的强度,变量之间的联系关系意味着在某种水平上一个变量的值可由别的的值举行展望。经由过程前往一个-1~1之间的一个数,相干系数给出了联系关系的强度,0暗示不相干。SAMPLE:下例前往1998年代发卖支出和月单元发卖的干系的积累系数(本例在SH用户下运转)SELECTt.calendar_month_number,CORR(SUM(s.amount_sold),SUM(s.quantity_sold))OVER(ORDERBYt.calendar_month_number)asCUM_CORRFROMsaless,timestWHEREs.time_id=t.time_idANDcalendar_year=1998GROUPBYt.calendar_month_numberORDERBYt.calendar_month_number;CALENDAR_MONTH_NUMBERCUM_CORR-------------------------------1213.9943093824.8520408755.8466522046.8712506287.9100298038.9175563999.92015435610.8672025111.84486476512.903542662COVAR_POP功效形貌:前往一对表达式的整体协方差。SAMPLE:下例CUM_COVP前往订价和最小产物代价的积累整体协方差SELECTproduct_id,supplier_id,COVAR_POP(list_price,min_price)OVER(ORDERBYproduct_id,supplier_id)ASCUM_COVP,COVAR_SAMP(list_price,min_price)OVER(ORDERBYproduct_id,supplier_id)ASCUM_COVSFROMproduct_informationpWHEREcategory_id=29ORDERBYproduct_id,supplier_id;PRODUCT_IDSUPPLIER_IDCUM_COVPCUM_COVS-----------------------------------------1774103088017751030871473.252946.517941030961702.777782554.1666718251030931926.252568.3333320041030861591.41989.2520051030861512.5181524161030881475.979591721.97619..COVAR_SAMP功效形貌:前往一对表达式的样本协方差SAMPLE:下例CUM_COVS前往订价和最小产物代价的积累样本协方差SELECTproduct_id,supplier_id,COVAR_POP(list_price,min_price)OVER(ORDERBYproduct_id,supplier_id)ASCUM_COVP,COVAR_SAMP(list_price,min_price)OVER(ORDERBYproduct_id,supplier_id)ASCUM_COVSFROMproduct_informationpWHEREcategory_id=29ORDERBYproduct_id,supplier_id;PRODUCT_IDSUPPLIER_IDCUM_COVPCUM_COVS-----------------------------------------1774103088017751030871473.252946.517941030961702.777782554.1666718251030931926.252568.3333320041030861591.41989.2520051030861512.5181524161030881475.979591721.97619..COUNT功效形貌:对一组内产生的事变举行积累计数,假如指定*或一些非空常数,count将对一切行计数,假如指定一个表达式,count前往表达式非空赋值的计数,当有不异值呈现时,这些相称的值城市被归入被盘算的值;可使用DISTINCT来纪录往失落一组中完整不异的数据后呈现的行数。SAMPLE:上面例子上钩算每一个员工在按薪水排序中以后行四周薪水在[n-50,n+150]之间的行数,n暗示以后行的薪水比方,Philtanker的薪水2200,排在他之前的行中薪水年夜于即是2200-50的有1行,排在他以后的行中薪水小于即是2200+150的行没有,以是count计数值cnt3为2(包含本人以后行);cnt2值相称于小于即是以后行的SALARY值的一切行数SELECTlast_name,salary,COUNT(*)OVER()AScnt1,COUNT(*)OVER(ORDERBYsalary)AScnt2,COUNT(*)OVER(ORDERBYsalaryRANGEBETWEEN50PRECEDINGAND150FOLLOWING)AScnt3FROMemployees;LAST_NAMESALARYCNT1CNT2CNT3-----------------------------------------------------------------Olson210010713Markle220010732Philtanker220010732Landry240010758Gee240010758Colmenares25001071110Patel25001071110..CUME_DIST功效形貌:盘算一行在组中的绝对地位,CUME_DIST老是前往年夜于0、小于或即是1的数,该数暗示该行在N行中的地位。比方,在一个3行的组中,前往的累计散布值为1/3、2/3、3/3SAMPLE:下例上钩算每一个工种的员工按薪水排序顺次积累呈现的散布百分比SELECTjob_id,last_name,salary,CUME_DIST()OVER(PARTITIONBYjob_idORDERBYsalary)AScume_distFROMemployeesWHEREjob_idLIKEPU%;JOB_IDLAST_NAMESALARYCUME_DIST-------------------------------------------------------PU_CLERKColmenares2500.2PU_CLERKHimuro2600.4PU_CLERKTobias2800.6PU_CLERKBaida2900.8PU_CLERKKhoo31001PU_MANRaphaely110001DENSE_RANK功效形貌:依据ORDERBY子句中表达式的值,从查询前往的每行,盘算它们与别的行的绝对地位。组内的数据按ORDERBY子句排序,然后给每行赋一个号,从而构成一个序列,该序列从1入手下手,今后累加。每次ORDERBY表达式的值产生变更时,该序列也随之增添。有一样值的行失掉一样的数字序号(以为null时相称的)。麋集的序列前往的时没有距离的数SAMPLE:下例上钩算每一个员工按部门分区再按薪水排序,顺次呈现的序列号(注重与RANK函数的区分)SELECTd.department_id,e.last_name,e.salary,DENSE_RANK()OVER(PARTITIONBYe.department_idORDERBYe.salary)asdrankFROMemployeese,departmentsdWHEREe.department_id=d.department_idANDd.department_idIN(60,90);DEPARTMENT_IDLAST_NAMESALARYDRANK----------------------------------------------------------60Lorentz4200160Austin4800260Pataballa4800260Ernst6000360Hunold9000490Kochhar17000190DeHaan17000190King240002FIRST功效形貌:从DENSE_RANK前往的汇合中掏出排在最后面的一个值的行(大概多行,由于值大概相称),因而完全的语法必要在入手下手处加上一个汇合函数以从中掏出纪录SAMPLE:上面例子中DENSE_RANK按部门分区,再按佣金commission_pct排序,FIRST掏出佣金最低的对应的一切行,然后后面的MAX函数从这个汇合中掏出薪水最低的值;LAST掏出佣金最高的对应的一切行,然后后面的MIN函数从这个汇合中掏出薪水最高的值SELECTlast_name,department_id,salary,MIN(salary)KEEP(DENSE_RANKFIRSTORDERBYcommission_pct)OVER(PARTITIONBYdepartment_id)"Worst",MAX(salary)KEEP(DENSE_RANKLASTORDERBYcommission_pct)OVER(PARTITIONBYdepartment_id)"Best"FROMemployeesWHEREdepartment_idin(20,80)ORDERBYdepartment_id,salary;LAST_NAMEDEPARTMENT_IDSALARYWorstBest--------------------------------------------------------------------Fay206000600013000Hartstein2013000600013000Kumar806100610014000Banda806200610014000Johnson806200610014000Ande806400610014000Lee806800610014000Tuvault807000610014000Sewall807000610014000Marvins807200610014000Bates807300610014000...FIRST_VALUE功效形貌:前往组中数据窗口的第一个值。SAMPLE:上面例子盘算按部门分区按薪水排序的数据窗口的第一个值对应的名字,假如薪水的第一个值有多个,则从多个对应的名字中取缺省排序的第一个名字SELECTdepartment_id,last_name,salary,FIRST_VALUE(last_name)OVER(PARTITIONBYdepartment_idORDERBYsalaryASC)ASlowest_salFROMemployeesWHEREdepartment_idin(20,30);DEPARTMENT_IDLAST_NAMESALARYLOWEST_SAL--------------------------------------------------------------20Fay6000Fay20Hartstein13000Fay30Colmenares2500Colmenares30Himuro2600Colmenares30Tobias2800Colmenares30Baida2900Colmenares30Khoo3100Colmenares30Raphaely11000ColmenaresLAG功效形貌:能够会见了局会合的别的行而不必举行自毗连。它同意去向理游标,就仿佛游标是一个数组一样。在给定组中可参考以后行之前的行,如许就能够从组中与以后行一同选择之前的行。Offset是一个正整数,其默许值为1,若索引超越窗口的局限,就前往默许值(默许前往的是组中第一行),其相反的函数是LEADSAMPLE:上面的例子中列prev_sal前往按hire_date排序的前1行的salary值SELECTlast_name,hire_date,salary,LAG(salary,1,0)OVER(ORDERBYhire_date)ASprev_salFROMemployeesWHEREjob_id=PU_CLERK;LAST_NAMEHIRE_DATESALARYPREV_SAL-------------------------------------------------------Khoo18-5月-9531000Tobias24-7月-9728003100Baida24-12月-9729002800Himuro15-11月-9826002900Colmenares10-8月-9925002600LAST功效形貌:从DENSE_RANK前往的汇合中掏出排在最初面的一个值的行(大概多行,由于值大概相称),因而完全的语法必要在入手下手处加上一个汇合函数以从中掏出纪录SAMPLE:上面例子中DENSE_RANK按部门分区,再按佣金commission_pct排序,FIRST掏出佣金最低的对应的一切行,然后后面的MAX函数从这个汇合中掏出薪水最低的值;LAST掏出佣金最高的对应的一切行,然后后面的MIN函数从这个汇合中掏出薪水最高的值SELECTlast_name,department_id,salary,MIN(salary)KEEP(DENSE_RANKFIRSTORDERBYcommission_pct)OVER(PARTITIONBYdepartment_id)"Worst",MAX(salary)KEEP(DENSE_RANKLASTORDERBYcommission_pct)OVER(PARTITIONBYdepartment_id)"Best"FROMemployeesWHEREdepartment_idin(20,80)ORDERBYdepartment_id,salary;LAST_NAMEDEPARTMENT_IDSALARYWorstBest--------------------------------------------------------------------Fay206000600013000Hartstein2013000600013000Kumar806100610014000Banda806200610014000Johnson806200610014000Ande806400610014000Lee806800610014000Tuvault807000610014000Sewall807000610014000Marvins807200610014000Bates807300610014000...LAST_VALUE功效形貌:前往组中数据窗口的最初一个值。SAMPLE:上面例子盘算按部门分区按薪水排序的数据窗口的最初一个值对应的名字,假如薪水的最初一个值有多个,则从多个对应的名字中取缺省排序的最初一个名字SELECTdepartment_id,last_name,salary,LAST_VALUE(last_name)OVER(PARTITIONBYdepartment_idORDERBYsalary)AShighest_salFROMemployeesWHEREdepartment_idin(20,30);DEPARTMENT_IDLAST_NAMESALARYHIGHEST_SAL------------------------------------------------------------20Fay6000Fay20Hartstein13000Hartstein30Colmenares2500Colmenares30Himuro2600Himuro30Tobias2800Tobias30Baida2900Baida30Khoo3100Khoo30Raphaely11000RaphaelyLEAD功效形貌:LEAD与LAG相反,LEAD能够会见组中以后行以后的行。Offset是一个正整数,其默许值为1,若索引超越窗口的局限,就前往默许值(默许前往的是组中第一行)SAMPLE:上面的例子中每行的"NextHired"前往按hire_date排序的下一行的hire_date值SELECTlast_name,hire_date,LEAD(hire_date,1)OVER(ORDERBYhire_date)AS"NextHired"FROMemployeesWHEREdepartment_id=30;LAST_NAMEHIRE_DATENextHired-------------------------------------------Raphaely07-DEC-9418-MAY-95Khoo18-MAY-9524-JUL-97Tobias24-JUL-9724-DEC-97Baida24-DEC-9715-NOV-98Himuro15-NOV-9810-AUG-99Colmenares10-AUG-99MAX功效形貌:在一个组中的数据窗口中查找表达式的最年夜值。SAMPLE:上面例子中dept_max前往以后行地点部门的最年夜薪水值SELECTdepartment_id,last_name,salary,MAX(salary)OVER(PARTITIONBYdepartment_id)ASdept_maxFROMemployeesWHEREdepartment_idin(10,20,30);DEPARTMENT_IDLAST_NAMESALARYDEPT_MAX----------------------------------------------------------10Whalen4400440020Hartstein130001300020Fay60001300030Raphaely110001100030Khoo31001100030Baida29001100030Tobias28001100030Himuro26001100030Colmenares250011000MIN功效形貌:在一个组中的数据窗口中查找表达式的最小值。SAMPLE:上面例子中dept_min前往以后行地点部门的最小薪水值SELECTdepartment_id,last_name,salary,MIN(salary)OVER(PARTITIONBYdepartment_id)ASdept_minFROMemployeesWHEREdepartment_idin(10,20,30);DEPARTMENT_IDLAST_NAMESALARYDEPT_MIN----------------------------------------------------------10Whalen4400440020Hartstein13000600020Fay6000600030Raphaely11000250030Khoo3100250030Baida2900250030Tobias2800250030Himuro2600250030Colmenares25002500NTILE功效形貌:将一个组分为"表达式"的散列暗示,比方,假如表达式=4,则给组中的每行分派一个数(从1到4),假如组中有20行,则给前5行分派1,给下5行分派2等等。假如组的基数不克不及由表达式值均匀分隔,则对这些行举行分派时,组中就没有任何percentile的行数比别的percentile的行数凌驾一行,最低的percentile是那些具有分外行的percentile。比方,若表达式=4,行数=21,则percentile=1的有5行,percentile=2的有5行等等。SAMPLE:下例中把6行数据分为4份SELECTlast_name,salary,NTILE(4)OVER(ORDERBYsalaryDESC)ASquartileFROMemployeesWHEREdepartment_id=100;LAST_NAMESALARYQUARTILE---------------------------------------------Greenberg120001Faviet90001Chen82002Urman78002Sciarra77003Popp69004PERCENT_RANK功效形貌:和CUME_DIST(积累分派)函数相似,关于一个组中给定的行来讲,在盘算那行的序号时,先减1,然后除以n-1(n为组中一切的行数)。该函数老是前往0~1(包含1)之间的数。SAMPLE:下例中假如Khoo的salary为2900,则pr值为0.6,由于RANK函数关于等值的前往序列值是一样的SELECTdepartment_id,last_name,salary,PERCENT_RANK()OVER(PARTITIONBYdepartment_idORDERBYsalary)ASprFROMemployeesWHEREdepartment_id<50ORDERBYdepartment_id,salary;DEPARTMENT_IDLAST_NAMESALARYPR----------------------------------------------------------10Whalen4400020Fay6000020Hartstein13000130Colmenares2500030Himuro26000.230Tobias28000.430Baida29000.630Khoo31000.830Raphaely11000140Mavris65000PERCENTILE_CONT功效形貌:前往一个与输出的散布百分比值绝对应的数据值,散布百分比的盘算办法见函数PERCENT_RANK,假如没有恰好对应的数据值,就经由过程上面算法来失掉值:RN=1+(P*(N-1))个中P是输出的散布百分比值,N是组内的行数CRN=CEIL(RN)FRN=FLOOR(RN)if(CRN=FRN=RN)then(valueofexpressionfromrowatRN)else(CRN-RN)*(valueofexpressionforrowatFRN)+(RN-FRN)*(valueofexpressionforrowatCRN)注重:本函数与PERCENTILE_DISC的区分在找不到对应的散布值时前往的替换值的盘算办法分歧SAMPLE:鄙人例中,关于部门60的Percentile_Cont值盘算以下:P=0.7N=5RN=1+(P*(N-1)=1+(0.7*(5-1))=3.8CRN=CEIL(3.8)=4FRN=FLOOR(3.8)=3(4-3.8)*4800+(3.8-3)*6000=5760SELECTlast_name,salary,department_id,PERCENTILE_CONT(0.7)WITHINGROUP(ORDERBYsalary)OVER(PARTITIONBYdepartment_id)"Percentile_Cont",PERCENT_RANK()OVER(PARTITIONBYdepartment_idORDERBYsalary)"Percent_Rank"FROMemployeesWHEREdepartment_idIN(30,60);LAST_NAMESALARYDEPARTMENT_IDPercentile_ContPercent_Rank---------------------------------------------------------------------------Colmenares25003030000Himuro26003030000.2Tobias28003030000.4Baida29003030000.6Khoo31003030000.8Raphaely110003030001Lorentz42006057600Austin48006057600.25Pataballa48006057600.25Ernst60006057600.75Hunold90006057601PERCENTILE_DISC功效形貌:前往一个与输出的散布百分比值绝对应的数据值,散布百分比的盘算办法见函数CUME_DIST,假如没有恰好对应的数据值,就取年夜于该散布值的下一个值。注重:本函数与PERCENTILE_CONT的区分在找不到对应的散布值时前往的替换值的盘算办法分歧SAMPLE:下例中0.7的散布值在部门30中没有对应的Cume_Dist值,以是就取下一个散布值0.83333333所对应的SALARY来替换SELECTlast_name,salary,department_id,PERCENTILE_DISC(0.7)WITHINGROUP(ORDERBYsalary)OVER(PARTITIONBYdepartment_id)"Percentile_Disc",CUME_DIST()OVER(PARTITIONBYdepartment_idORDERBYsalary)"Cume_Dist"FROMemployeesWHEREdepartment_idin(30,60);LAST_NAMESALARYDEPARTMENT_IDPercentile_DiscCume_Dist-------------------------------------------------------------------------Colmenares2500303100.166666667Himuro2600303100.333333333Tobias2800303100.5Baida2900303100.666666667Khoo3100303100.833333333Raphaely110003031001Lorentz4200606000.2Austin4800606000.6Pataballa4800606000.6Ernst6000606000.8Hunold90006060001RANK功效形貌:依据ORDERBY子句中表达式的值,从查询前往的每行,盘算它们与别的行的绝对地位。组内的数据按ORDERBY子句排序,然后给每行赋一个号,从而构成一个序列,该序列从1入手下手,今后累加。每次ORDERBY表达式的值产生变更时,该序列也随之增添。有一样值的行失掉一样的数字序号(以为null时相称的)。但是,假如两行切实其实失掉一样的排序,则序数将随后腾跃。若两行序数为1,则没有序数2,序列将给组中的下一行分派值3,DENSE_RANK则没有任何腾跃。SAMPLE:下例上钩算每一个员工按部门分区再按薪水排序,顺次呈现的序列号(注重与DENSE_RANK函数的区分)SELECTd.department_id,e.last_name,e.salary,RANK()OVER(PARTITIONBYe.department_idORDERBYe.salary)asdrankFROMemployeese,departmentsdWHEREe.department_id=d.department_idANDd.department_idIN(60,90);DEPARTMENT_IDLAST_NAMESALARYDRANK----------------------------------------------------------60Lorentz4200160Austin4800260Pataballa4800260Ernst6000460Hunold9000590Kochhar17000190DeHaan17000190King240003RATIO_TO_REPORT功效形貌:该函数盘算expression/(sum(expression))的值,它给出相对总数的百分比,即以后行对sum(expression)的奉献。SAMPLE:下例盘算每一个员工的人为占该类员工总人为的百分比SELECTlast_name,salary,RATIO_TO_REPORT(salary)OVER()ASrrFROMemployeesWHEREjob_id=PU_CLERK;LAST_NAMESALARYRR---------------------------------------------Khoo3100.223021583Baida2900.208633094Tobias2800.201438849Himuro2600.18705036Colmenares2500.179856115REGR_(LinearRegression)Functions功效形貌:这些线性回回函数合适最小二乘法回回线,有9个分歧的回回函数可以使用。REGR_SLOPE:前往斜率,即是COVAR_POP(expr1,expr2)/VAR_POP(expr2)REGR_INTERCEPT:前往回回线的y截距,即是AVG(expr1)-REGR_SLOPE(expr1,expr2)*AVG(expr2)REGR_COUNT:前往用于添补回回线的非空数字对的数量REGR_R2:前往回回线的决意系数,盘算式为:IfVAR_POP(expr2)=0thenreturnNULLIfVAR_POP(expr1)=0andVAR_POP(expr2)!=0thenreturn1IfVAR_POP(expr1)>0andVAR_POP(expr2!=0thenreturnPOWER(CORR(expr1,expr),2)REGR_AVGX:盘算回回线的自变量(expr2)的均匀值,往失落了空对(expr1,expr2)后,即是AVG(expr2)REGR_AVGY:盘算回回线的应变量(expr1)的均匀值,往失落了空对(expr1,expr2)后,即是AVG(expr1)REGR_SXX:前往值即是REGR_COUNT(expr1,expr2)*VAR_POP(expr2)REGR_SYY:前往值即是REGR_COUNT(expr1,expr2)*VAR_POP(expr1)REGR_SXY:前往值即是REGR_COUNT(expr1,expr2)*COVAR_POP(expr1,expr2)(上面的例子都是在SH用户下完成的)SAMPLE1:下例盘算1998年最初三个礼拜中两种产物(260和270)在周末的发卖量中已开辟票数目和总数目的积累斜率和回回线的截距SELECTt.fiscal_month_number"Month",t.day_number_in_month"Day",REGR_SLOPE(s.amount_sold,s.quantity_sold)OVER(ORDERBYt.fiscal_month_desc,t.day_number_in_month)ASCUM_SLOPE,REGR_INTERCEPT(s.amount_sold,s.quantity_sold)OVER(ORDERBYt.fiscal_month_desc,t.day_number_in_month)ASCUM_ICPTFROMsaless,timestWHEREs.time_id=t.time_idANDs.prod_idIN(270,260)ANDt.fiscal_year=1998ANDt.fiscal_week_numberIN(50,51,52)ANDt.day_number_in_weekIN(6,7)ORDERBYt.fiscal_month_desc,t.day_number_in_month;MonthDayCUM_SLOPECUM_ICPT----------------------------------------1212-6818721212-6818721213-20.2448981254.367351213-20.2448981254.367351219-18.8260871287122062.4561404125.28655122062.4561404125.28655122062.4561404125.28655122062.4561404125.28655122667.265822858.9712313122667.265822858.9712313122737.5245541284.958221122737.5245541284.958221122737.5245541284.958221SAMPLE2:下例盘算1998年4月天天的积累买卖数目SELECTUNIQUEt.day_number_in_month,REGR_COUNT(s.amount_sold,s.quantity_sold)OVER(PARTITIONBYt.fiscal_month_numberORDERBYt.day_number_in_month)"Regr_Count"FROMsaless,timestWHEREs.time_id=t.time_idANDt.fiscal_year=1998ANDt.fiscal_month_number=4;DAY_NUMBER_IN_MONTHRegr_Count-----------------------------1825216503247543300...26214503022200SAMPLE3:下例盘算1998年每个月发卖量中已开辟票数目和总数目的积累回回线决意系数SELECTt.fiscal_month_number,REGR_R2(SUM(s.amount_sold),SUM(s.quantity_sold))OVER(ORDERBYt.fiscal_month_number)"Regr_R2"FROMsaless,timestWHEREs.time_id=t.time_idANDt.fiscal_year=1998GROUPBYt.fiscal_month_numberORDERBYt.fiscal_month_number;FISCAL_MONTH_NUMBERRegr_R2-----------------------------1213.9273729844.8070199725.9327455676.946828617.9653420118.9557680759.95954261810.93861857511.88093141512.882769189SAMPLE4:下例盘算1998年12月最初两周产物260的发卖量中已开辟票数目和总数目的积累均匀值SELECTt.day_number_in_month,REGR_AVGY(s.amount_sold,s.quantity_sold)OVER(ORDERBYt.fiscal_month_desc,t.day_number_in_month)"Regr_AvgY",REGR_AVGX(s.amount_sold,s.quantity_sold)OVER(ORDERBYt.fiscal_month_desc,t.day_number_in_month)"Regr_AvgX"FROMsaless,timestWHEREs.time_id=t.time_idANDs.prod_id=260ANDt.fiscal_month_desc=1998-12ANDt.fiscal_week_numberIN(51,52)ORDERBYt.day_number_in_month;DAY_NUMBER_IN_MONTHRegr_AvgYRegr_AvgX---------------------------------------1488224.51488224.51580122.251580122.2516777.621.618642.85714317.857142918642.85714317.857142920589.516.3752154415.111111122592.36363616.454545522592.36363616.454545524553.84615415.384615424553.84615415.38461542652214.527578.416.0666667SAMPLE5:下例盘算产物260和270在1998年2月周末发卖量中已开辟票数目和总数目的积累REGR_SXY,REGR_SXX,andREGR_SYY统计值SELECTt.day_number_in_month,REGR_SXY(s.amount_sold,s.quantity_sold)OVER(ORDERBYt.fiscal_year,t.fiscal_month_desc)"Regr_sxy",REGR_SYY(s.amount_sold,s.quantity_sold)OVER(ORDERBYt.fiscal_year,t.fiscal_month_desc)"Regr_syy",REGR_SXX(s.amount_sold,s.quantity_sold)OVER(ORDERBYt.fiscal_year,t.fiscal_month_desc)"Regr_sxx"FROMsaless,timestWHEREs.time_id=你可以配置MySQL运行在微小的嵌入式应用程序中,处理的数据可能不足1Mb??而你也可以用它来处理数Tb的数据。MySQL获得这种可扩展性的路径之一是通过一个人们所熟知的存储过程,这是一个运行在程序之外的微型、预编译程序。 |
|