MyBatis怎么实现set和SELECT同时存在的MySQL查询语句

这段查询语句怎么用MyBatis实现?

  set @num1 = 0,@num2 = 0,@num3 = 0,@num4 = 0;
      select     t1.license_number,t1.begin_time,t2.entry_time
    FROM
    (SELECT (@num1 := @num1 + 1) AS number,bulldozer_info.* FROM bulldozer_info WHERE license_number = "京OFV501FV606" ORDER BY BEGIN_time ) t1
    LEFT JOIN
    (SELECT (@num2 := @num2 + 1) AS number,refuse_treatment_plant.* FROM refuse_treatment_plant where license_number = "京OFV501FV606" ORDER BY entry_time ) t2
    on t1.license_number = t2.license_number  and t1.number = t2.number
    UNION
    select     t1.license_number,t1.begin_time,t2.entry_time
    FROM
    (SELECT (@num3 := @num3 + 1) AS number,bulldozer_info.* FROM bulldozer_info WHERE license_number = "京OFV501FV606" ORDER BY BEGIN_time ) t1
    RIGHT  JOIN
    (SELECT (@num4 := @num4 + 1) AS number,refuse_treatment_plant.* FROM refuse_treatment_plant where license_number = "京OFV501FV606" ORDER BY entry_time ) t2
    on t1.license_number = t2.license_number  and t1.number = t2.number
阅读 2.6k
1 个回答

MyBatis 本身就可以多语句
数据库可能需要开多语句,比如MySQL要给URL加 allowMultiQueries=true

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题