mysql case when 查询一个效率问题
问题描述
第一种:
SELECT `user`.username, `user`.email, `user`.id AS user_id, user_class.level_id, user_class.class_id AS cid, user_class.create_time AS bontime, class.graduation_time, class.offline_graduation_time, class.is_baidan, class. NAME AS class, class.period_id, class.offline_period_id, company. NAME AS branch, company.id AS bidFROM `user_class`INNER JOIN `user` ON user_class.user_id = `user`.idINNER JOIN class ON user_class.class_id = class.idLEFT JOIN company ON class.company_id = company.idLEFT JOIN period ON class.period_id = period.idWHERE class. DISABLE = 1AND class.is_baidan IN (’1’, ’2’)AND `user_class`.level_id IN (’10’, ’12’, ’14’)AND CASEWHEN is_baidan = 1 THEN class.graduation_time=0 OR class.graduation_time > 1469980800WHEN is_baidan = 2 THEN class.offline_graduation_time = 0 OR class.offline_graduation_time > 1469980800END;
第二种:
SELECT `user`.username, `user`.email, `user`.id AS user_id, user_class.level_id, user_class.class_id AS cid, user_class.create_time AS bontime, class.graduation_time AS eontime, class.offline_graduation_time, class.is_baidan, class. NAME AS class, class.period_id, class.offline_period_id, company. NAME AS branch, company.id AS bidFROM `user_class`INNER JOIN `user` ON user_class.user_id = `user`.idINNER JOIN class ON user_class.class_id = class.idLEFT JOIN company ON class.company_id = company.idLEFT JOIN period ON class.period_id = period.idWHERE class. DISABLE = 1AND `user_class`.level_id IN (’10’, ’12’, ’14’)AND ( (class.is_baidan = 1 AND (class.graduation_time = 0 OR class.graduation_time > 1469980800) ) OR (class.is_baidan = 2 AND (class.offline_graduation_time=0 OR class.offline_graduation_time >1469980800) ));
这两个sql语句查询结果相同,想问问到底是哪个好一点
问题解答
回答1:看mysql的执行计划,你这个sql语句不执行执行计划看,我觉得谁也告知不了你准确的答案,因为他们没有非常明显的性能差异。
相关文章:
1. javascript - h5上的手机号默认没有识别2. javascript - 谁能帮我创建一个webpack2+vue2+vuex+less+dev-server的空项目3. vue.js - weex scroller搭配refresh在android平台上拉会触发refresh4. python - 网站显示的图片与爬虫获取到的图片不同,应该如何确定问题?5. 极光推送 - Android app消息推送 百度 极光 个推 信鸽哪个好一些?6. css3 - Firefox 字号相对IE、Chrome更大,如何在CSS中统一?7. css - div display: inline-block; 置中?8. html5 - 如何让H5页面在手机浏览器里和微信全屏显示9. javascript - 在html中写了个<video>视频,浏览器却是一片空白为什么呢?360浏览器?10. javascript - ajax中的 textStatus 报错为 parsererror?