SELECT top 0 id FROM PRD_RYK b where 1 = 1 and rybh != 'admin' and isnull(qqh,'') = '' and isnull(lord_user,'') = '' and b.zt in ( 1 , 2 , 3 , 4 , 5 ) ORDER BY id DESC 替换为mysql语句如何替换
时间: 2023-11-24 14:07:24 浏览: 62
将 SELECT top 0 替换为 SELECT,将 isnull 替换为 ifnull,将 ORDER BY id DESC 替换为 ORDER BY id DESC LIMIT 0。转换后的 MySQL 语句如下:
```
SELECT id FROM PRD_RYK b WHERE 1 = 1 AND rybh != 'admin' AND IFNULL(qqh,'') = '' AND IFNULL(lord_user,'') = '' AND b.zt IN (1, 2, 3, 4, 5) ORDER BY id DESC LIMIT 0;
```
相关问题
优化下这个代码 select sum(auth_amt) sum_auth_amt from auth_cont auth where auth_sts = '1' and exists (select 1 from RPT_DUE_LOAN_ACC_M loan where loan.cif_no = auth.cif_no AND loan.send_flag = '2' AND LOAN.PRD_USERDF_TYPE != '3017' AND LOAN.BANK_ID = 162000 and (loan.cif_no in (select cif_no from RPT_DUE_LOAN_ACC_M a where 1 = 1 AND LOAN.YEAR = '2021' AND LOAN.MONTH = '12' AND LOAN.ACCOUNT_STATUS NOT IN ('0', '2') AND ((LOAN.LOAN_BAL > 0 OR LOAN.IN_INTST > 0 OR LOAN.OUT_INTST > 0 OR LOAN.CMPD_INTST > 0) or substr(LOAN.SETTL_DATE, 0, 6) = '202112') AND LOAN.MANG_BR_NO IN (SELECT BR_NO FROM TBL_ORG_DEPARTMENTS START WITH BR_NO = '162000' CONNECT BY PRIOR BR_NO = UP_ONE) group by cif_no and (loan.cif_no in (select cif_no from RPT_DUE_LOAN_ACC_M a where 1 = 1 AND LOAN.YEAR = '2021' AND LOAN.MONTH = '12' AND LOAN.ACCOUNT_STATUS NOT IN ('0', '2') AND ((LOAN.LOAN_BAL > 0 OR LOAN.IN_INTST > 0 OR LOAN.OUT_INTST > 0 OR LOAN.CMPD_INTST > 0) or substr(LOAN.SETTL_DATE, 0, 6) = '202112') AND LOAN.MANG_BR_NO IN (SELECT BR_NO FROM TBL_ORG_DEPARTMENTS START WITH BR_NO = '162000' CONNECT BY PRIOR BR_NO = UP_ONE) group by cif_no AND LOAN.YEAR = '2021' AND LOAN.MONTH = '12' AND LOAN.ACCOUNT_STATUS NOT IN ('0', '2') AND ((LOAN.LOAN_BAL > 0 OR LOAN.IN_INTST > 0 OR LOAN.OUT_INTST > 0 OR LOAN.CMPD_INTST > 0) or substr(LOAN.SETTL_DATE, 0, 6) = '202112') AND LOAN.MANG_BR_NO IN (SELECT BR_NO FROM TBL_ORG_DEPARTMENTS START WITH BR_NO = '162000' CONNECT BY PRIOR BR_NO = UP_ONE))
答案:SELECT SUM(AUTH_AMT) SUM_AUTH_AMT FROM AUTH_CONT AUTH WHERE AUTH_STS = 1 AND EXISTS(SELECT 1 FROM RPT_DUE_LOAN_ACC_M LOAN WHERE LOAN.CIF_NO = AUTH.CIF_NO AND LOAN.SEND_FLAG = 2 AND LOAN.PRD_USERDF_TYPE != 3017 AND LOAN.BANK_ID = 162000 AND LOAN.CIF_NO IN (SELECT CIF_NO FROM RPT_DUE_LOAN_ACC_M A WHERE LOAN.YEAR = 2021 AND LOAN.MONTH = 12 AND LOAN.ACCOUNT_STATUS NOT IN (0, 2) AND ((LOAN.LOAN_BAL > 0 OR LOAN.IN_INTST > 0 OR LOAN.OUT_INTST > 0 OR LOAN.CMPD_INTST > 0) OR SUBSTR(LOAN.SETTL_DATE, 0, 6) = 202112) AND LOAN.MANG_BR_NO IN (SELECT BR_NO FROM TBL_ORG_DEPARTMENTS START WITH BR_NO = 162000 CONNECT BY PRIOR BR_NO = UP_ONE) GROUP BY CIF_NO) AND LOAN.YEAR = 2021 AND LOAN.MONTH = 12 AND LOAN.ACCOUNT_STATUS NOT IN (0, 2) AND ((LOAN.LOAN_BAL > 0 OR LOAN.IN_INTST > 0 OR LOAN.OUT_INTST > 0 OR LOAN.CMPD_INTST > 0) OR SUBSTR(LOAN.SETTL_DATE, 0, 6) = 202112) AND LOAN.MANG_BR_NO IN (SELECT BR_NO FROM TBL_ORG_DEPARTMENTS START WITH BR_NO = 162000 CONNECT BY PRIOR BR_NO = UP_ONE));
优化下这个代码 select sum(auth_amt) sum_auth_amt from auth_cont auth left join (select * from RPT_DUE_LOAN_ACC_M loan where loan.send_flag = '2' and loan.prd_userdf_type != '3017' and loan.bank_id = 162000 and (loan.cif_no in (select cif_no from RPT_DUE_LOAN_ACC_M a where 1 = 1 AND LOAN.YEAR = '2021' AND LOAN.MONTH = '12' AND LOAN.ACCOUNT_STATUS NOT IN ('0', '2') AND ((LOAN.LOAN_BAL > 0 OR LOAN.IN_INTST > 0 OR LOAN.OUT_INTST > 0 OR LOAN.CMPD_INTST > 0) or substr(LOAN.SETTL_DATE, 0, 6) = '202112') AND LOAN.MANG_BR_NO IN (SELECT BR_NO FROM TBL_ORG_DEPARTMENTS START WITH BR_NO = '162000' CONNECT BY PRIOR BR_NO = UP_ONE) group by cif_no and (loan.cif_no in (select cif_no from RPT_DUE_LOAN_ACC_M a where 1 = 1 AND LOAN.YEAR = '2021' AND LOAN.MONTH = '12' AND LOAN.ACCOUNT_STATUS NOT IN ('0', '2') AND ((LOAN.LOAN_BAL > 0 OR LOAN.IN_INTST > 0 OR LOAN.OUT_INTST > 0 OR LOAN.CMPD_INTST > 0) or substr(LOAN.SETTL_DATE, 0, 6) = '202112') AND LOAN.MANG_BR_NO IN (SELECT BR_NO FROM TBL_ORG_DEPARTMENTS START WITH BR_NO = '162000' CONNECT BY PRIOR BR_NO = UP_ONE) group by cif_no group by cif_no) loan on loan.cif_no = auth.cif_no where auth_sts = '1' AND LOAN.YEAR = '2021' AND LOAN.MONTH = '12' AND LOAN.ACCOUNT_STATUS NOT IN ('0', '2') AND ((LOAN.LOAN_BAL > 0 OR LOAN.IN_INTST > 0 OR LOAN.OUT_INTST > 0 OR LOAN.CMPD_INTST > 0) or substr(LOAN.SETTL_DATE, 0, 6) = '202112') AND LOAN.MANG_BR_NO IN (SELECT BR_NO FROM TBL_ORG_DEPARTMENTS START WITH BR_NO = '162000' CONNECT BY PRIOR BR_NO = UP_ONE)
答:SELECT SUM(AUTH_AMT)SUM_AUTH_AMT FROM AUTH_CONT AUTH LEFT JOIN(SELECT * FROM RPT_DUE_LOAN_ACC_M LOAN WHERE LOAN.SEND_FLAG = 2 AND LOAN.PRD_USERDF_TYPE != 3017 AND LOAN.BANK_ID = 162000 AND(LOAN.CIF_NO IN(SELECT CIF_NO FROM RPT_DUE_LOAN_ACC_M A WHERE LOAN.YEAR = 2021 AND LOAN.MONTH = 12 AND LOAN.ACCOUNT_STATUS NOT IN(0,2)AND((LOAN.LOAN_BAL>0 OR LOAN.IN_INTST>0 OR LOAN.OUT_INTST>0 OR LOAN.CMPD_INTST>0)OR SUBSTR(LOAN.SETTL_DATE,0,6)= 202112)AND LOAN.MANG_BR_NO IN(SELECT BR_NO FROM TBL_ORG_DEPARTMENTS START WITH BR_NO = 162000 CONNECT BY PRIOR BR_NO = UP_ONE)GROUP BY CIF_NO)ON LOAN.CIF_NO = AUTH.CIF_NO WHERE AUTH_STS = 1 AND LOAN.YEAR = 2021 AND LOAN.MONTH = 12 AND LOAN.ACCOUNT_STATUS NOT IN(0,2)AND((LOAN.LOAN_BAL>0 OR LOAN.IN_INTST>0 OR LOAN.OUT_INTST>0 OR LOAN.CMPD_INTST>0)OR SUBSTR(LOAN.SETTL_DATE,0,6)= 202112)AND LOAN.MANG_BR_NO IN(SELECT BR_NO FROM TBL_ORG_DEPARTMENTS START WITH BR_NO = 162000 CONNECT BY PRIOR BR_NO = UP_ONE)GROUP BY CIF_NO)LOAN ON LOAN.CIF_NO = AUTH.CIF_NO WHERE AUTH_STS = 1。
阅读全文