In doing a polling project, there is a function that requires the number of votes to be detected before the bottom 10.
The following SQL is used here:
SELECT MIN from vote_candidate WHERE > 0 GROUP by ORDERby DESC
After the completion of the question of the cardiac, in the End Is min () first execution, or limit first effective?
According to the previous understanding, the priority of limit is in the where, GROUP by, and ORDER by, is to limit the result set of the last return, presumably it is executed after the aggregation function, then this limit clause is meaningless, the resulting is not the expected result.
In practice, some test data are added to the table. An unexpected conclusion was drawn through the test:
The precedence of aggregation functions when they coexist with the limit clause is divided into two cases:
1. There is a GROUP BY clause (in this case): WHERE > Group by > ORDER by > LIMIT > Aggregation
2. No GROUP BY clause: WHERE > Aggregation > ORDER by > LIMIT
MySQL aggregate function and limit