nvl(t.valid_type,2)<>1
时间: 2024-05-09 21:12:10 浏览: 145
nvl(t.valid_type,2)是一个SQL语句中的函数,它的作用是判断字段t.valid_type的值是否为空,如果为空则返回2,否则返回t.valid_type的值。而<>1是一个条件判断,表示不等于1。所以整个表达式nvl(t.valid_type,2)<>1的含义是判断字段t.valid_type的值是否不等于1,如果不等于1则返回True,否则返回False。
相关问题
优化这个sql SELECT count( 1 ) FROM ( SELECT B.ID, B.PURCHASE_REQUEST_ID, B.MATERIAL_ID, B.MATERIAL_CODE, B.MATERIAL_NAME, B.STANDARD, B.MODEL_ID, B.BILL_ROW_ID, B.BILL_NO, BILL_NAME, B.MODEL_CODE, B.MODEL_NAME, B.PARENT_MODEL_ID, B.PARENT_MODEL_CODE, B.PARENT_MODEL_NAME, B.UNIT_CODE, B.UNIT_NAME, B.PURCHASE_TYPE_CODE, CAST( NVL( B.APPLY_NUM, 0 ) AS NUMBER ( 24, 10 ) ) AS APPLY_NUM, CAST( NVL( B.DEAL_NUM, 0 ) AS NUMBER ( 24, 10 ) ) AS DEAL_NUM, CAST( NVL( B.RETURN_NUM, 0 ) AS NUMBER ( 24, 10 ) ) AS RETURN_NUM, B.DEAL_USER_ID, B.DEAL_USER_NAME, CAST( NVL( B.PRICE, 0 ) AS NUMBER ( 24, 10 ) ) AS PRICE, CAST( NVL( B.AMOUNT, 0 ) AS NUMBER ( 24, 10 ) ) AMOUNT, B.IMPLEMENT_CODE, B.IMPLEMENT_NAME, B.IMPLEMENT_INVEST_AMOUNT, B.PURCHASE_MANAGER_ID, B.PURCHASE_MANAGER_NAME, B.PROVIDER_ID, B.PROVIDER_NAME, B.REMARK, B.DELIVER_AREA, B.DELIVER_ADDRESS, B.RECEIVE_PEOPLE, B.RECEIVE_PEOPLE_PHONE, B.ITEM_STATUS, B.COST_CENTER, B.COST_BUDGET_CODE, B.COST_IMPLEMENT_NAME, B.FRAME_CONT_ID, B.FRAME_CONT_CODE, B.FRAME_CONT_NAME, B.DETAIL_CONFIG, B.PURCHASE_CATEGORY_CODE, B.INVOICE_TITLE_CODE, B.INVOICE_SEND_ADDRRSS, B.MATERIAL_REQUEST_ITEM_ID, B.YEAR, B.DELETE_FLAG, B.PROVINCE_CODE, B.REASON, B.PARENT_ITEM_ID, B.FRAME_CONT_ITEM_ID, B.SUB_MATERIAL_REQUEST_ID, B.SUB_MATERIAL_REQUEST_CODE, B.MATERIAL_URL, B.RECOMMEND_PROVIDER_NAMES, C.PURCHASE_REQUEST_CODE, C.PURCHASE_REQUEST_NAME, C.APPLY_TYPE_CODE, C.CREATOR_NAME, C.APPLY_TELEPHONE, C.COMPANY_NAME, C.DEPT_NAME, B.CREATE_TIME, TO_CHAR( B.CREATE_TIME, 'YYYY-MM-DD' ) CREATE_TIME_STR, C.ARRIVE_TIME, C.IS_TO_END, C.MONEY_WAY_CODE, C.OWN, C.APPLY_CATEGORY_CODE, C.manu_Type, C.BILL_ID, MMD.MATERIAL_TYPE_CODE, B.BRANCH_COMPANY_DEAL_USER_ID, B.BRANCH_COMPANY_DEAL_USER_NAME, ( SELECT ORG_NAME FROM ORGANIZATIONS WHERE DELETE_FLAG = '0' AND ORG_CODE = ( SELECT PARENT_COMPANY_NO FROM ORGANIZATIONS WHERE ID = B.MATERIAL_DEPT_ID )) AS MATERIAL_COMPANY_NAME, B.ORIGINAL, B.PROVIDER_PRODUCT_MODEL, B.PROVIDER_PRODUCT_NAME, B.PRODUCT_DESC, B.Back_Flag, CASE WHEN MMD.material_type_code = 'WZ' THEN '1' WHEN MMD.material_type_code = 'FW' THEN '2' ELSE '3' END apply_category_code_item, NVL( C.IS_CARDSYSTEM_REQUEST, '0' ) IS_CARDSYSTEM_REQUEST, B.APPLY_GROUP_AUTHORITES, B.SCIENTIFIC_RESEARCH_ID, B.SCIENTIFIC_RESEARCH_CODE, B.SCIENTIFIC_RESEARCH_NAME, B.PREQUALFY_CODE, nvl( C.IS_QUICK, '0' ) AS IS_QUICK, C.PURCHASE_WAY_CODE, C.PURCHASE_TYPE_CODE PURCHASE_TYPE_CODE_P, C.ORIGINAL_TYPE, C.PURCHASE_REQUEST_BILLS_TYPE, B.IS_FRAME_CONT_MONAD FROM PURCHASE_REQUEST_ITEM B LEFT JOIN PURCHASE_REQUEST C ON B.PURCHASE_REQUEST_ID = C.ID LEFT JOIN MATERIAL_DATA MMD ON MMD.ID = B.MATERIAL_ID AND MMD.DELETE_FLAG = '0' WHERE B.delete_flag = '0' AND B.Item_Status IN ( 1 ) AND NOT EXISTS ( SELECT * FROM purchase_request_item_log pril WHERE B.id = pril.purchase_request_item_id AND pril.lock_status = '1' AND pril.delete_flag = '0' ) AND ( ( c.apply_type_code NOT IN ( '20', '41', '3' ) AND nvl( B.Apply_Num, 0 ) > nvl( B.Deal_Num, 0 )) OR c.apply_type_code IN ( '20', '41', '3' ) ) AND B.Deal_User_Id =: 1 AND C.MONEY_WAY_CODE =: 2 AND C.APPLY_TYPE_CODE =: 3 AND C.PAY_OUT_TYPE_CODE =: 4 AND C.APPLY_CATEGORY_CODE =: 5 AND NVL( C.IS_CARDSYSTEM_REQUEST, '0' ) = : 6 AND NOT EXISTS ( SELECT * FROM purchase_request_item p left join material_province mp ON p.material_id = mp.material_id WHERE p.delete_flag = 0 AND mp.delete_flag = 0 AND mp.material_status = 03 AND mp.org_code = p.province_code AND p.id = B.id ) ORDER BY C.ID, B.ID ASC)
首先,可以将子查询中的所有列名改为别名,这样可以避免重名和提高代码可读性。另外,可以尝试使用 EXISTS 子查询来替换 NOT EXISTS 子查询,因为 EXISTS 子查询的性能通常更好。最后,可以考虑对 WHERE 子句中的多个条件进行逻辑上的分组,以避免出现过于复杂的条件表达式。下面是优化后的 SQL:
SELECT COUNT(1)
FROM (
SELECT
b.ID,
b.PURCHASE_REQUEST_ID,
b.MATERIAL_ID,
b.MATERIAL_CODE,
b.MATERIAL_NAME,
b.STANDARD,
b.MODEL_ID,
b.BILL_ROW_ID,
b.BILL_NO,
b.BILL_NAME,
b.MODEL_CODE,
b.MODEL_NAME,
b.PARENT_MODEL_ID,
b.PARENT_MODEL_CODE,
b.PARENT_MODEL_NAME,
b.UNIT_CODE,
b.UNIT_NAME,
b.PURCHASE_TYPE_CODE,
CAST(NVL(b.APPLY_NUM, 0) AS NUMBER(24, 10)) AS APPLY_NUM,
CAST(NVL(b.DEAL_NUM, 0) AS NUMBER(24, 10)) AS DEAL_NUM,
CAST(NVL(b.RETURN_NUM, 0) AS NUMBER(24, 10)) AS RETURN_NUM,
b.DEAL_USER_ID,
b.DEAL_USER_NAME,
CAST(NVL(b.PRICE, 0) AS NUMBER(24, 10)) AS PRICE,
CAST(NVL(b.AMOUNT, 0) AS NUMBER(24, 10)) AMOUNT,
b.IMPLEMENT_CODE,
b.IMPLEMENT_NAME,
b.IMPLEMENT_INVEST_AMOUNT,
b.PURCHASE_MANAGER_ID,
b.PURCHASE_MANAGER_NAME,
b.PROVIDER_ID,
b.PROVIDER_NAME,
b.REMARK,
b.DELIVER_AREA,
b.DELIVER_ADDRESS,
b.RECEIVE_PEOPLE,
b.RECEIVE_PEOPLE_PHONE,
b.ITEM_STATUS,
b.COST_CENTER,
b.COST_BUDGET_CODE,
b.COST_IMPLEMENT_NAME,
b.FRAME_CONT_ID,
b.FRAME_CONT_CODE,
b.FRAME_CONT_NAME,
b.DETAIL_CONFIG,
b.PURCHASE_CATEGORY_CODE,
b.INVOICE_TITLE_CODE,
b.INVOICE_SEND_ADDRRSS,
b.MATERIAL_REQUEST_ITEM_ID,
b.YEAR,
b.DELETE_FLAG,
b.PROVINCE_CODE,
b.REASON,
b.PARENT_ITEM_ID,
b.FRAME_CONT_ITEM_ID,
b.SUB_MATERIAL_REQUEST_ID,
b.SUB_MATERIAL_REQUEST_CODE,
b.MATERIAL_URL,
b.RECOMMEND_PROVIDER_NAMES,
c.PURCHASE_REQUEST_CODE,
c.PURCHASE_REQUEST_NAME,
c.APPLY_TYPE_CODE,
c.CREATOR_NAME,
c.APPLY_TELEPHONE,
c.COMPANY_NAME,
c.DEPT_NAME,
b.CREATE_TIME,
TO_CHAR(b.CREATE_TIME, 'YYYY-MM-DD') CREATE_TIME_STR,
c.ARRIVE_TIME,
c.IS_TO_END,
c.MONEY_WAY_CODE,
c.OWN,
c.APPLY_CATEGORY_CODE,
c.manu_Type,
c.BILL_ID,
MMD.MATERIAL_TYPE_CODE,
b.BRANCH_COMPANY_DEAL_USER_ID,
b.BRANCH_COMPANY_DEAL_USER_NAME,
(SELECT ORG_NAME FROM ORGANIZATIONS WHERE DELETE_FLAG = '0' AND ORG_CODE = (SELECT PARENT_COMPANY_NO FROM ORGANIZATIONS WHERE ID = b.MATERIAL_DEPT_ID)) AS MATERIAL_COMPANY_NAME,
b.ORIGINAL,
b.PROVIDER_PRODUCT_MODEL,
b.PROVIDER_PRODUCT_NAME,
b.PRODUCT_DESC,
b.Back_Flag,
CASE
WHEN MMD.material_type_code = 'WZ' THEN '1'
WHEN MMD.material_type_code = 'FW' THEN '2'
ELSE '3'
END apply_category_code_item,
NVL(c.IS_CARDSYSTEM_REQUEST, '0') IS_CARDSYSTEM_REQUEST,
b.APPLY_GROUP_AUTHORITES,
b.SCIENTIFIC_RESEARCH_ID,
b.SCIENTIFIC_RESEARCH_CODE,
b.SCIENTIFIC_RESEARCH_NAME,
b.PREQUALFY_CODE,
NVL(c.IS_QUICK, '0') AS IS_QUICK,
c.PURCHASE_WAY_CODE,
c.PURCHASE_TYPE_CODE PURCHASE_TYPE_CODE_P,
c.ORIGINAL_TYPE,
c.PURCHASE_REQUEST_BILLS_TYPE,
b.IS_FRAME_CONT_MONAD
FROM PURCHASE_REQUEST_ITEM b
LEFT JOIN PURCHASE_REQUEST c ON b.PURCHASE_REQUEST_ID = c.ID
LEFT JOIN MATERIAL_DATA MMD ON MMD.ID = b.MATERIAL_ID AND MMD.DELETE_FLAG = '0'
WHERE b.delete_flag = '0'
AND b.Item_Status IN (1)
AND b.Deal_User_Id = :1
AND C.MONEY_WAY_CODE = :2
AND C.APPLY_TYPE_CODE = :3
AND C.PAY_OUT_TYPE_CODE = :4
AND C.APPLY_CATEGORY_CODE = :5
AND NVL(C.IS_CARDSYSTEM_REQUEST, '0') = :6
AND EXISTS (
SELECT *
FROM purchase_request_item_log pril
WHERE B.id = pril.purchase_request_item_id
AND pril.lock_status = '1'
AND pril.delete_flag = '0'
)
AND (
c.apply_type_code IN ('20', '41', '3')
OR (
c.apply_type_code NOT IN ('20', '41', '3')
AND NVL(b.Apply_Num, 0) > NVL(b.Deal_Num, 0)
)
)
AND NOT EXISTS (
SELECT *
FROM purchase_request_item p
LEFT JOIN material_province mp ON p.material_id = mp.material_id
WHERE p.delete_flag = 0
AND mp.delete_flag = 0
AND mp.material_status = 03
AND mp.org_code = p.province_code
AND p.id = b.id
)
ORDER BY c.ID, b.ID ASC
)
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写法
我可以帮你将这段 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` 并做一些处理。
阅读全文