请下列将Oracle语句转为mysql语句 CASE WHEN t.pm_mp_machine_id = 'JJY213' THEN ROUND(t.STOPTIME/60, 0) ELSE ROUND((t.STOPTIME - (CASE WHEN t.no > 1 THEN COALESCE(LAG(t.STOPTIME, 1) OVER(PARTITION BY t.producedate, t.pb_shift_id, t.pm_mp_machine_id, t.pm_mp_stopcode_id ORDER BY t.no), 0) ELSE 0 END))/60, 0) END AS STOPTIME
时间: 2024-04-19 17:25:43 浏览: 107
以下是将Oracle语句转换为MySQL语句的示例:
CASE WHEN t.pm_mp_machine_id = 'JJY213' THEN ROUND(t.STOPTIME/60, 0) ELSE ROUND((t.STOPTIME - COALESCE((SELECT lag(t2.STOPTIME) FROM MT_DC_PM_MP_PT110DATA t2 WHERE t2.producedate = t.producedate AND t2.pb_shift_id = t.pb_shift_id AND t2.pm_mp_machine_id = t.pm_mp_machine_id AND t2.pm_mp_stopcode_id = t.pm_mp_stopcode_id AND t2.no < t.no ORDER BY t2.no DESC LIMIT 1), 0))/60, 0) END AS STOPTIME
请注意,MySQL中的LAG函数在子查询中不能与ORDER BY一起使用,因此在这里进行了调整。另外,MySQL中的LIMIT子句用于限制子查询结果的行数。
相关问题
请下列将Oracle语句转为mysql语句 CASE WHEN t.pm_mp_machine_id = 'JJY213' THEN ROUND(t.STOPTIME/60, 0) ELSE ROUND((t.STOPTIME - COALESCE((SELECT lag(t2.STOPTIME) FROM MT_DC_PM_MP_PT110DATA t2 WHERE t2.producedate = t.producedate AND t2.pb_shift_id = t.pb_shift_id AND t2.pm_mp_machine_id = t.pm_mp_machine_id AND t2.pm_mp_stopcode_id = t.pm_mp_stopcode_id AND t2.no < t.no ORDER BY t2.no DESC LIMIT 1), 0))/60, 0) END AS STOPTIME
以下是将Oracle语句转换为MySQL语句的示例:
CASE WHEN t.pm_mp_machine_id = 'JJY213' THEN ROUND(t.STOPTIME/60, 0) ELSE ROUND((t.STOPTIME - COALESCE((SELECT t2.STOPTIME FROM MT_DC_PM_MP_PT110DATA t2 WHERE t2.producedate = t.producedate AND t2.pb_shift_id = t.pb_shift_id AND t2.pm_mp_machine_id = t.pm_mp_machine_id AND t2.pm_mp_stopcode_id = t.pm_mp_stopcode_id AND t2.no < t.no ORDER BY t2.no DESC LIMIT 1), 0))/60, 0) END AS STOPTIME
请注意,MySQL中的LAG函数在子查询中不能与ORDER BY一起使用,因此在这里进行了调整。另外,MySQL中的LIMIT子句用于限制子查询结果的行数。
请下列将Oracle语句转为mysql语句 decode(t.pm_mp_machine_id,'JJY213',ROUND(t.STOPTIME/60,0),ROUND(( t.STOPTIME-(case when t.no>1 then nvl(lag(t.STOPTIME,1) over(partition by t.producedate,t.pb_shift_id,t.pm_mp_machine_id,t.pm_mp_stopcode_id order by t.no),0) else 0 end ))/60,0 )) AS STOPTIME
在MySQL中,你可以使用CASE语句来模拟Oracle中的DECODE函数,并使用ROUND函数进行四舍五入。以下是将Oracle语句转换为MySQL语句的示例:
CASE WHEN t.pm_mp_machine_id = 'JJY213' THEN ROUND(t.STOPTIME/60, 0) ELSE ROUND((t.STOPTIME - (CASE WHEN t.no > 1 THEN COALESCE(LAG(t.STOPTIME, 1) OVER(PARTITION BY t.producedate, t.pb_shift_id, t.pm_mp_machine_id, t.pm_mp_stopcode_id ORDER BY t.no), 0) ELSE 0 END))/60, 0) END AS STOPTIME
请注意,MySQL中使用COALESCE函数来代替Oracle中的NVL函数,并使用ROUND函数进行四舍五入。
阅读全文