资源描述:
《hibernate分组与聚合查询(hibernate groups and aggregate queries)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、hibernate分组与聚合查询(Hibernategroupsandaggregatequeries)Learningwebsite:http://blog.csdn.net/hardwin/article/details/4330912Hibernategroupingandaggregationqueries(nativeSQLandHQLusingcasewhenthenelseend)UsenativeSQLforqueriesusinghibernateTheviewplaincopytoclipboardprint?//serverdeploymentstati
2、sticsqueryclassIdcStatisticSpecPublicclassIdcStatisticSpecextendsAbstQueryStringSpec{/**machineroomID*/PrivateIntegercompLocaId;/**thestarttimeofthequeryPrivateDatebeginDate;/*****PrivateDateendDate;//omitgetsetPublicStringthequeryString(){StringBufferSQL=newStringBuffer("SELECTappcalledsim
3、plyMRL,app.OPERATION_ID,app.ThePRODUCT_ID,"+"sum"(if(cab.type='ONSHOW',1,0))asonshowNumber,""Sum"(if(cab.Type='WITHDRAW',1,0))as"Sum"(if(cab.Type='MOVE',1,0))asmoveNumber,""+"sum(cab.Type='WITHDRAW'andcab.reversion='RETURN',1,0))asreturnNumber"+"FROMchanage_applyapp,chanage_cabinetscab,chan
4、age_cabinets_executeexe"+"WHEREapp.Id=cab.APPLICATION_IDANDapp.id=exe.APPLICATION_ID"+"ANDapp.MRLisnotnullANDapp.mrl!=0"+"ANDapp.operation_idisnotnullANDapp.operation_id!=0"+"ANDapp.product_idisnotnullANDapp.product_id!=0"+"ANDexe.Attitude='Y'");If(QuerySpecUtil.Valid(compLocaId)){SQL.Appen
5、d("ANDapp.CalledsimplyMRL=:compLocaId");}If(QuerySpecUtil.Valid(beginDate)){SQL.Append("ANDexeEXECUTE_TIME>=:beginDate");}If(QuerySpecUtil.Valid(endDate)){SQL.Append("ANDexeEXECUTE_TIME<=:endDate");}SQL.Append("GROUPBYappcalledsimplyMRL,app.OPERATION_ID,app.ThePRODUCT_ID");ReturntheSQL.Thet
6、oString();}@OverrideProtectedvoidreset(){CompLocaId=null;BeginDate=null;EndDate=null;}}//serverdeploymentstatisticsqueryclassIdcStatisticSpecPublicclassIdcStatisticSpecextendsAbstQueryStringSpec{/**machineroomID*/PrivateIntegercompLocaId;/**thestarttimeofthequery私人beginDate日期;/**查询的结束时间*/私人
7、endDate日期;//省略得到设置公共字符串变量(){StringBuffersql=新的StringBuffer(“选择app.MRL、app.OPERATION_IDapp.PRODUCT_ID。”+sum(如果(cab.type='ONSHOW'1,0))作为onshowNumber“sum”(如果(cab.type='撤退',1,0))作为撤军的数量+sum(如果(cab.type='移动',1,0))作为moveNumber+"和(如果(出租车。类型='撤退'和cab.降级='返回',1,0