Home > database >  About SQL optimization problem
About SQL optimization problem

Time:11-07

To the written test ran into a problem today,
About 10 million article in one of the staff table data, with an efficient SQL statements and salary> 9999 and age> 35, salary & gt; 9999 and the age & lt; 35, salary & lt; 9999 and age> 35, salary & lt; 9999 and age<35, four interval number,
O bosses give advice or comments

CodePudding user response:

SELECT
The SUM (CASE WHEN salary & gt; 9999 and the age & gt; 35 THEN 1 ELSE 0 END),
The SUM (CASE WHEN salary & gt; 9999 and the age & lt; 35 THEN 1 ELSE 0 END),
The SUM (CASE WHEN salary & lt; 9999 and the age & gt; 35 THEN 1 ELSE 0 END),
The SUM (CASE WHEN salary & lt; 9999 and the age & lt; 35 THEN 1 ELSE 0 END)
The FROM TABLE_NAME
1, there is a loophole, is salary=9999 and age=35 data will be lost,
2, if the salary and age are integers, can put the salary & gt; 9999 modified into salary & gt;=10000, and other such change,
3, the best in terms of salary and the age index,
4, if there is a partition, each partition can statistics of the results, and then sum,
  • Related