First, the purpose of SQL writing is to solve the problem, so only to understand the problem to solve, to write more efficient SQL statements, to gracefully solve the problem, to get more happiness!
When writing an SQL statement, think like an optimizer, ask yourself these questions, and believe that long-time accumulation results will make your SQL efficient and elegant.
1) What tables are needed to get all the data you need?
2) Are there any tables that are partitioned? If so, how are partitions defined?
3) What are the columns for each table?
4) What are the indexes that can be referenced in each table?
5) What are the statistics for each table and the columns and indexes in it?
6) Are there histogram information on some columns? (This thing doesn't know what it is)
Through the above questions. and the rational placement of the search conditions before and after the order, to a certain extent less detours, improve the efficiency of SQL
For example, when using multiple and, put the most likely false first, if you use or to put the most likely to be true in front, as much as possible to use and less use OR and so on
A high-quality SQL starts with asking questions (notes)