下面这段SQL语句,修改成MySQL语句;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
时间: 2024-02-10 10:25:05 浏览: 78
在MySQL中,LAG函数的语法略有不同。以下是将给定的Oracle SQL语句转换为等效的MySQL语句:
```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,
IF(N = 1 AND BAL_ORI IS NULL, 1234567890, BAL_ORI) BAL_ORI,
IF(N = 1 AND BAL_LOC IS NULL, 1234567890, BAL_LOC) 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中的语法稍有不同,不需要使用IGNORE NULLS参数。在IF语句中,用IF来替代CASE语句来进行条件判断。
阅读全文