「已注销」 2016-12-22 09:22 采纳率: 28.6%
浏览 6407

mybatis动态创建临时表

场景:mybatis中一段sql是分页查询,查询中有个查询条件是in一个传入的list,极端情况下这个list会变得很大,导致sql报错。应该怎么解决?
考虑过建临时表,但是还没查询到在select语句里面创建临时表的例子

  • 写回答

1条回答 默认 最新

  • engchina 2016-12-27 01:21
    关注

    参考URL:http://blog.csdn.net/engchina/article/details/48250829

    使用with,试试下面这个2个方法可不可以。(exists性能比in性能好,请根据需要选择)

    1,用in的写法

    with TEMP_TABLE_A as (
    select
    t1.c1
    from
    Table1 t1
    )

    select
    t2.c1
    from
    Table2 t2
    where
    t2.c1 in (
    select
    temp.c1
    from
    TEMP_TABLE_A temp

    )

    2,用exists的写法
    

    with TEMP_TABLE_A as (
    select 
        t1.c1 
    from 
        Table1 t1
    

    )

    select
    t2.c1
    from
    Table2 t2
    where
    exists (
    select
    1
    from
    TEMP_TABLE_A temp
    where t2.c1 = temp.c1
    )
    ==================================

    评论

报告相同问题?

悬赏问题

  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗