1. Case Take all employees who are not the head of the company and group them by age! select age as 'age', count(*) as 'number of people' from t_emp where id not in (select ceo from t_dept where ceo is not null) group by age; How to optimize? ①Solve the full table scan of the dept table and create an index for the ceo field: At this time, query again: ② Further optimization, replace not in. The above SQL can be replaced with: select age as 'age',count(*) as 'number of people' from emp e left join dept d on e.id=d.ceo where d.id is null group by age; Conclusion: When judging the range, try not to use not in and not exists, use left join on xxx is null instead. Summarize The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links You may also be interested in:
|
<<: How to use firewall iptables strategy to forward ports on Linux servers
>>: Detailed example of using useState in react
Table of contents 1. Page Layout 2. Image upload ...
Table of contents Previous words Synchronous and ...
This article example shares the specific code for...
Effect display The built-in boot interface is too...
The so-called container actually creates a readab...
MySQL is a very powerful relational database. How...
After setting up the MySQL master-slave, you ofte...
When creating a tomcat server on a local eclipse,...
MySQL filtering timing of where conditions and ha...
Table of contents 1. The role of watch in vue is ...
Table of contents Ideas Request interception Resp...
Wildcard categories: %Percent wildcard: indicates...
1. Import echart in HTML file <!-- Import echa...
Put your own web project in the webapps directory...
Table of contents 1. What is Promise? 2. Why is t...