merge into MFM_ACCOMMODATION_STANDARD a using ( <foreach collection="areaIds" item="areaId" separator="union"> select #{areaId,jdbcType=VARCHAR} AREA_ID, #{rankId,jdbcType=VARCHAR} RANK_ID, #{year,jdbcType=VARCHAR} YEAR from dual </foreach> )c on ( a.AREA ID = c.AREA_ID and a.RANK_ID = c.RANK_ID and a.YEAR = c.YEAR when matched then update set a.STAND_VALVE = #{standValue}, a.IS_SHOW = 1 when not matched then insent (a.ID,a.AREA_ID, a.RANK_ID,a.YEAR,a.STANDVALUE, a.order_id, a.IS_SHOW)values (null,C.AREA_ID, #{rankId),#{year},#{standValve},#{order},1)改写为mysql
时间: 2024-03-21 11:40:01 浏览: 145
我刚刚给你的SQL语句包含 Oracle 数据库的语法,如果你要将该语句转换为 MySQL 数据库的语法,你可以使用以下 SQL 语句:
```
INSERT INTO MFM_ACCOMMODATION_STANDARD
(ID, AREA_ID, RANK_ID, YEAR, STANDVALUE, order_id, IS_SHOW)
SELECT
null,
c.AREA_ID,
#{rankId},
#{year},
#{standValue},
#{order},
1
FROM
(SELECT #{areaIds[0]} AS AREA_ID
UNION
SELECT #{areaIds[1]} AS AREA_ID
UNION
-- 可以加入更多的 areaIds
SELECT #{areaIds[n]} AS AREA_ID) c
LEFT JOIN
MFM_ACCOMMODATION_STANDARD a
ON
a.AREA_ID = c.AREA_ID
AND a.RANK_ID = #{rankId}
AND a.YEAR = #{year}
WHEN MATCHED THEN
UPDATE SET
a.STAND_VALVE = #{standValue},
a.IS_SHOW = 1
WHEN NOT MATCHED THEN
INSERT (ID, AREA_ID, RANK_ID, YEAR, STANDVALUE, order_id, IS_SHOW)
VALUES (null, c.AREA_ID, #{rankId}, #{year}, #{standValue}, #{order}, 1)
```
请注意,在 MySQL 中,我们不能使用 `FROM DUAL` 的语法,因此,我们使用 `SELECT` 语句来生成我们的虚拟表。此外,我们还使用了 `LEFT JOIN` 来确保我们没有遗漏任何区域。
阅读全文