为了帮助大家更好的学习mysql,这篇文章主要介绍了mysql max 与 where 间的执行问题小结,需要的朋友可以参考下,希望对大家有所帮助。
mysql max 与 where 间的执行问题
执行sql:
create table `grades` (
`id` int(20) not null auto_increment,
`student_id` int(20) not null,
`subject` 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`,`subject`,`grades`) values (1,1,'语文','80'),(2,1,'数学','89'),(3,2,'语文','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 `student`(`id`,`name`) values (1,'xiaoming'),(2,'xiaohong'),(3,'xiaobai');
执行结果:
执行结果1:
执行结果2:
执行结果3:
执行结果4:
执行结果5:
由此可见:
1.max是在where条件之前执行的,
2.而group by 又是在max之前执行的
3.当where 与 group by 同时出现 优先执行where条件
总结
以上所述是小编给大家介绍的mysql max 与 where 间的执行问题小结,希望对大家有所帮助。
相关推荐:
mysql where 条件
mysql where语句优化
出现mysql max-connections问题解决
以上就是关于mysql max 与 where 间的执行问题小结的详细内容。