WITH t AS ( SELECT NVL(t2.FINANCIER,t2.ISSUER) customerId, NVL(NVL(t1.TDY_FLOAT_INGPL, 0) + NVL(t1.DSC_COST_AMT, 0),0) AS amount FROM PTL_SEC_VALUTION t1 INNER JOIN FIN_PRODUCT t2 ON t1.FINPROD_ID=t2.FINPROD_ID INNER JOIN FIN_PRODUCT_TYPE t3 ON t3.FINPROD_ID=t2.FINPROD_ID WHERE (t2.FINPROD_TYPE2='F01' OR (t2.FINPROD_TYPE2 ='F18' and t3.TYPE_6='P01' and t3.TYPE_7='1209') OR (t2.FINPROD_TYPE2 ='F18' and t3.TYPE_6='P11' )) AND t1.CDATE =to_date(#{valDate,jdbcType=VARCHAR},'yyyy-MM-dd')-1 ) select h.counterId from ( select n.counterId,n.amount from ( select m.counterId,sum(amount) amount from ( select t5.customer_Id counterId,T.AMOUNT from t INNER JOIN MST_CUSTOMER_INFO_ADD t5 on t5.customer_id=t.customerId where t5.INDUSTRY!='10' and t5.PARENT_CUSTOMER_ID is null union all select t6.customer_Id counterId,T.AMOUNT from t INNER JOIN MST_CUSTOMER_INFO_ADD t5 on t5.customer_id=t.customerId INNER JOIN MST_CUSTOMER_INFO_ADD t6 on t6.customer_id=t5.PARENT_CUSTOMER_ID where t5.INDUSTRY!='10' ) m group by m.counterId ) n order by n.amount desc ) h where rownum<![CDATA[<]]>11 改成ignite写法
时间: 2024-02-17 21:03:08 浏览: 170
oracleSelect.rar_Jsp/Servlet_SQL_
我可以帮你将这段 SQL 转换成 Ignite 的写法,以下是转换后的代码:
```java
IgniteCache<Object, Object> cache = ignite.getOrCreateCache("myCache");
SqlFieldsQuery query = new SqlFieldsQuery(
"WITH t AS (" +
" SELECT NVL(t2.FINANCIER, t2.ISSUER) customerId, " +
" NVL(NVL(t1.TDY_FLOAT_INGPL, 0) + NVL(t1.DSC_COST_AMT, 0), 0) AS amount " +
" FROM PTL_SEC_VALUTION t1 " +
" INNER JOIN FIN_PRODUCT t2 ON t1.FINPROD_ID = t2.FINPROD_ID " +
" INNER JOIN FIN_PRODUCT_TYPE t3 ON t3.FINPROD_ID = t2.FINPROD_ID " +
" WHERE (t2.FINPROD_TYPE2 = 'F01' " +
" OR (t2.FINPROD_TYPE2 = 'F18' AND t3.TYPE_6 = 'P01' AND t3.TYPE_7 = '1209') " +
" OR (t2.FINPROD_TYPE2 = 'F18' AND t3.TYPE_6 = 'P11')) " +
" AND t1.CDATE = to_date(?, 'yyyy-MM-dd') - 1" +
") " +
"SELECT h.counterId " +
"FROM (" +
" SELECT n.counterId, n.amount " +
" FROM (" +
" SELECT m.counterId, sum(amount) amount " +
" FROM (" +
" SELECT t5.customer_Id counterId, T.AMOUNT " +
" FROM t " +
" INNER JOIN MST_CUSTOMER_INFO_ADD t5 ON t5.customer_id = t.customerId " +
" WHERE t5.INDUSTRY != '10' AND t5.PARENT_CUSTOMER_ID IS NULL " +
" UNION ALL " +
" SELECT t6.customer_Id counterId, T.AMOUNT " +
" FROM t " +
" INNER JOIN MST_CUSTOMER_INFO_ADD t5 ON t5.customer_id = t.customerId " +
" INNER JOIN MST_CUSTOMER_INFO_ADD t6 ON t6.customer_id = t5.PARENT_CUSTOMER_ID " +
" WHERE t5.INDUSTRY != '10'" +
" ) m " +
" GROUP BY m.counterId " +
" ) n " +
" ORDER BY n.amount DESC" +
") h " +
"WHERE ROWNUM < 11"
);
query.setArgs(valDate);
try (QueryCursor<List<?>> cursor = cache.query(query)) {
for (List<?> row : cursor) {
Object counterId = row.get(0);
// Do something with the counterId
}
}
```
在上面的代码中,我们首先获取了一个 Ignite Cache 对象,然后创建了一个 `SqlFieldsQuery` 对象,将原来的 SQL 语句作为参数传递进去,并使用 `setArgs` 方法设置 SQL 语句中的参数值。最后,我们使用 `cache.query` 方法执行查询,并遍历结果集中的每一行数据,在其中获取 `counterId` 并做一些处理。
阅读全文