Execution problem between mysql max and where, mysqlmax
Execution problem between mysql max and where
Execute SQL:
Create table 'grades '(
'Id' int (20) not null AUTO_INCREMENT,
'Student _ id' int (20) not null,
'Subobject' varchar (20) COLLATE utf8_bin default null,
'Grades' varchar (20) COLLATE utf8_bin default null,
Primary key ('id ')
) ENGINE = InnoDB AUTO_INCREMENT = 4 default charset = utf8 COLLATE = utf8_bin;
Insert into 'grades' ('id', 'student _ id', 'subobject', 'grades') values (, 'China', '80, 'mat', '89 '), (, 'China', '90 ');
Create table 'student '(
'Id' int (20) not null AUTO_INCREMENT,
'Name' varchar (20) COLLATE utf8_bin default null,
Primary key ('id ')
) ENGINE = InnoDB AUTO_INCREMENT = 4 default charset = utf8 COLLATE = utf8_bin;
Insert into 'studen' ('id', 'name') values (1, 'xiaoming'), (2, 'xiaohong '), (3, 'xiaoba ');
Execution result:
Result 1:
Result 2:
Result 3:
Result 4:
Result 5:
It can be seen that:
1. max is executed before the where condition,
2. group by is executed before max.
3. When both the where and group by statements give priority to where statements