<code>SELECT B.dict_data_name, SUM(A.pv) AS pv FROM shw_mo_health_news A INNER JOIN bas_dict_data B ON A.third_name_dictid = B.item_id WHERE A.class_level = 3 AND B.class_id = 1012 AND A.collect_date >= '2016-04-01' AND A.collect_date <= '2016-05-31' GROUP BY A.third_name_dictid ORDER BY pv DESC;</code>
The actual query time for users is about 0.6S
View with explain:
<code>SELECT B.dict_data_name, A.PV FROM ( SELECT hn.third_name_dictid, SUM(hn.pv) AS PV FROM shw_mo_health_news hn WHERE hn.class_level = 3 AND hn.collect_date >= '2016-04-01' AND hn.collect_date <= '2016-05-31' GROUP BY hn.third_name_dictid ) A, ( SELECT dd.item_id, dd.dict_data_name FROM bas_dict_data dd WHERE dd.class_id = 1012 ) B WHERE A.third_name_dictid = B.item_id ORDER BY PV DESC</code>
The actual time is about 0.03s
Explain View
Why is there such a big difference in the efficiency of these two query methods?
Many people on the Internet say that the efficiency of these two writing methods is almost the same; but my one is 0.6 and the other is 0.03, the difference between the two is quite big. What is the cause of this? Is it because there is a problem with the SQl statement I wrote or is it for other reasons?