首页 > 数据库技术 > 详细

mysql in 子查询 效率慢,对比

时间:2017-08-07 19:50:48      阅读:318      评论:0      收藏:0      [点我收藏+]
技术分享
 desc SELECT id,detail,groupId from hs_knowledge_point where groupId in (
    SELECT groupId from hs_knowledge_point where groupId>0 GROUP BY groupId HAVING COUNT(groupId) > 1 
    UNION all
    SELECT groupId from hs_knowledge_point_commit where groupId>0 GROUP BY groupId HAVING COUNT(groupId) > 1 
)
UNION ALL
SELECT id,detail,groupId from hs_knowledge_point_commit where groupId in (
    SELECT groupId from hs_knowledge_point where groupId>0 GROUP BY groupId HAVING COUNT(groupId) > 1 
    UNION all
    SELECT groupId from hs_knowledge_point_commit where groupId>0 GROUP BY groupId HAVING COUNT(groupId) > 1 
)
View Code
技术分享
SELECT id,detail,groupId from hs_knowledge_point where groupId in (
    select groupId from (
        SELECT groupId from hs_knowledge_point where groupId>0 GROUP BY groupId HAVING COUNT(groupId) > 1 
        UNION all
        SELECT groupId from hs_knowledge_point_commit where groupId>0 GROUP BY groupId HAVING COUNT(groupId) > 1 
    ) tmp
)
UNION ALL
SELECT id,detail,groupId from hs_knowledge_point_commit where groupId in (
    select groupId from (
        SELECT groupId from hs_knowledge_point where groupId>0 GROUP BY groupId HAVING COUNT(groupId) > 1 
        UNION all
        SELECT groupId from hs_knowledge_point_commit where groupId>0 GROUP BY groupId HAVING COUNT(groupId) > 1 
    ) tmp
)
View Code

 

技术分享

技术分享

 

 

技术分享

技术分享

 

mysql in 子查询 效率慢,对比

原文:http://www.cnblogs.com/shixm/p/7300937.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!