用JPA连Oracle不可以使用的SQL语句


可以写成:


SELECT mo,cellname,bsc,region,town,Round(bpi24, 0),thour|| ':00',dhour,
       decode(result_,0,'网外干扰 - cdma杂散干扰',
                      1,'网内干扰 - 互调干扰',
                      2,'网内干扰 - 频点干扰',
                      3,'网内干扰 - 直放站干扰',
                      4,'网外干扰 - 直放站干扰',
                      5,'网内干扰',
                      6,'网外干扰',
                      7,'无法确定',
                      8,NULL,'其他'
       ) as result_,
       freq
FROM   cy_fasdata_itas ts
WHERE  1 = 1
       AND bpi24 > -1
       AND ttime = '2013-07-08'
       AND mo IN (SELECT mo
                  FROM   cy_fasdata_itas ts
                  WHERE  ttime IN ( '2013-07-08', '2013-07-01' )
                  GROUP  BY mo
                  HAVING Count(*) > 0
                  ) 



但是不可以写成:


SELECT mo,cellname,bsc,region,town,Round(bpi24, 0),thour|| ':00',dhour,
       CASE result_
       WHEN 0 THEN '网外干扰 - cdma杂散干扰'
       WHEN 1 THEN '网内干扰 - 互调干扰'
       WHEN 2 THEN '网内干扰 - 频点干扰'
       WHEN 3 THEN '网内干扰 - 直放站干扰'
       WHEN 4 THEN '网外干扰 - 直放站干扰'
       WHEN 5 THEN '网内干扰'
       WHEN 6 THEN '网外干扰'
       WHEN 7 THEN '无法确定'
       WHEN 8 THEN NULL
       ELSE '其他'
       END AS result_2,
       freq
FROM   cy_fasdata_itas ts
WHERE  1 = 1
       AND bpi24 > -1
       AND ttime = '2013-07-08'
       AND mo IN (SELECT mo
                  FROM   cy_fasdata_itas ts
                  WHERE  ttime IN ( '2013-07-08', '2013-07-01' )
                  GROUP  BY mo
                  HAVING Count(*) > 0
                  ) 



@Override
	public GridPager getPqGridBase(GridPager gridPager, WebToolBean webToolBean)throws Exception {
		String sqlCount = "select count(id) from CY_FASDATA_ITAS ts "+	gridPager.pGWhere("ts")+this.getSqlWheres(webToolBean)+" and mo in ( select mo  from  CY_FASDATA_ITAS ts where ttime in ('"+webToolBean.getTtime()+"','"+webToolBean.getTtime2()+"') group by mo having count(*)>"+webToolBean.getDay()+")";
		/*
		String sqlQuery = "select MO,CELLNAME,BSC,REGION,TOWN,round(BPI24,0),THOUR||':00',dhour," +
				" case result_ when 0 then '网外干扰-CDMA杂散干扰' when 1 then '网内干扰-互调干扰' WHEN 2 then '网内干扰-频点干扰' WHEN 3 then '网内干扰-直放站干扰' "+
				"WHEN 4 then '网外干扰-直放站干扰' WHEN 5 then '网内干扰' WHEN 6 then '网外干扰' WHEN 7 then '无法确定'  WHEN 8 then ''   ELSE '其他' END as result_,"+
				" FREQ from  CY_FASDATA_ITAS ts "+	gridPager.pGWhere("ts")+this.getSqlWheres(webToolBean);
		*/
		
		String sqlQuery = "select MO,CELLNAME,BSC,REGION,TOWN,round(BPI24,0),THOUR||':00',dhour," +
				" decode(result_,0,'网外干扰 - cdma杂散干扰',1,'网内干扰 - 互调干扰',2,'网内干扰 - 频点干扰',3,'网内干扰 - 直放站干扰',4,'网外干扰 - 直放站干扰',5,'网内干扰',6,'网外干扰',7,'无法确定',8,NULL,'其他') as result_,"+
				" FREQ from  CY_FASDATA_ITAS ts "+	gridPager.pGWhere("ts")+this.getSqlWheres(webToolBean)+" and mo in ( select mo  from  CY_FASDATA_ITAS ts where ttime in ('"+webToolBean.getTtime()+"','"+webToolBean.getTtime2()+"') group by mo having count(*)>"+webToolBean.getDay()+")";
		StringBuffer sbCount = new StringBuffer(sqlCount);
		StringBuffer sbQuery = new StringBuffer(sqlQuery);
		sbQuery.append(" order by ts."+gridPager.getSortBy()+" "+ gridPager.getDir());
		Query query = em.createNativeQuery(sbCount.toString());
		gridPager.pGParams(query, "ts");	
		this.setQueryParams(query, webToolBean);
		BigDecimal  count=(BigDecimal)query.getSingleResult();
		gridPager.setFullListSize(count.intValue());
		query = em.createNativeQuery(sbQuery.toString());
		gridPager.pGParams(query, "ts");	
		this.setQueryParams(query, webToolBean);
		query.setMaxResults(gridPager.getRecordPage());
		query.setFirstResult(gridPager.getStartIndex());
		List list = query.getResultList();
		gridPager.setList(StringUtil.toBoxListObject(list));
		gridPager.pGExportCSV(query,gridPager);
		return gridPager;
	}

你可能感兴趣的:(oracle)