SELECT * FROM (SELECT N, KJQJ, CODE_ORG, ZZNAME, GYSNAME, GYSBM, DJLX, NVL(BAL_ORI, LAG(BAL_ORI IGNORE NULLS) OVER(ORDER BY 1)) BAL_ORI, NVL(BAL_LOC, LAG(BAL_LOC IGNORE NULLS) OVER(ORDER BY 1)) BAL_LOC FROM (SELECT N, KJQJ, CODE_ORG, ZZNAME, GYSNAME, GYSBM, DJLX, CASE WHEN N = 1 AND BAL_ORI IS NULL THEN 1234567890 ELSE BAL_ORI END BAL_ORI, CASE WHEN N = 1 AND BAL_LOC IS NULL THEN 1234567890 ELSE BAL_LOC END BAL_LOC FROM T_PAYABLE_1_2 T)) TT WHERE TT.BAL_ORI != 1234567890 AND TT.BAL_LOC != 1234567890;修改成MySQL语句
时间: 2024-02-10 22:25:05 浏览: 90
在MySQL中,LAG函数的语法略有不同。以下是将给定的Oracle SQL语句转换为等效的MySQL语句:
```
SELECT *
FROM (
SELECT N,
KJQJ,
CODE_ORG,
ZZNAME,
GYSNAME,
GYSBM,
DJLX,
IFNULL(BAL_ORI, LAG(BAL_ORI) OVER(ORDER BY 1)) BAL_ORI,
IFNULL(BAL_LOC, LAG(BAL_LOC) OVER(ORDER BY 1)) BAL_LOC
FROM (
SELECT N,
KJQJ,
CODE_ORG,
ZZNAME,
GYSNAME,
GYSBM,
DJLX,
CASE
WHEN N = 1 AND BAL_ORI IS NULL THEN 1234567890
ELSE BAL_ORI
END BAL_ORI,
CASE
WHEN N = 1 AND BAL_LOC IS NULL THEN 1234567890
ELSE BAL_LOC
END BAL_LOC
FROM T_PAYABLE_1_2 T
) TT
) TT
WHERE TT.BAL_ORI != 1234567890
AND TT.BAL_LOC != 1234567890;
```
注意,MySQL中使用IFNULL函数来替代Oracle SQL中的NVL函数,以处理NULL值的替换。此外,LAG函数在MySQL中的语法稍有不同。
阅读全文