• sql语句in


      在今天之前sql一直用in语句,知道今天遇到一张数据量很大的表查了三分钟才查出来,这才意识到数据库优化有多重要.作为一名开发人员,首先从优化sql语句开始。

      之前用in写sql是这样的

    select * from m_package where userId in(  select id from sys_user where newDorm='2号楼' and `newRoomNumber` = 'N413') ;
    执行结果:/* 0 rows affected, 18 rows found. Duration for 1 query: 0.407 sec. */ 

      exists写sql语句

    select * from m_package as pack where
    exists (select id from sys_user as user where newDorm='2号楼' and `newRoomNumber` = 'N413' and pack.userId = user.id);
    执行结果:/* 0 rows affected, 18 rows found. Duration for 1 query: 0.297 sec. */ 

    inner join写sql语句

    select * from m_package as pack inner join sys_user as user where pack.userId = user.id and newDorm='2号楼' and `newRoomNumber` = 'N413';
    执行结果:/* 0 rows affected, 18 rows found. Duration for 1 query: 0.234 sec. */ 

    可以看出来执行效率 inner join > exists > in

  • 相关阅读:
    poj3041——最小点覆盖
    高斯消元
    hdu1704——floyd
    poj2594——最小路径覆盖
    POJ3020 二分图匹配——最小路径覆盖
    我的老博客
    [ZJOI2015]幻想乡战略游戏 动态点分治
    HDU 5737 Differencia set + 主席树
    HDU
    HDU
  • 原文地址:https://www.cnblogs.com/aeolian/p/8393030.html
Copyright © 2020-2023  润新知