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条件
总结
相关推荐
aydh 2020-11-12
yifangs 2020-10-13
CoderToy 2020-11-16
emmm00 2020-11-17
王艺强 2020-11-17
ribavnu 2020-11-16
bianruifeng 2020-11-16
wangshuangbao 2020-11-13
苏康申 2020-11-13
vivenwan 2020-11-13
moyekongling 2020-11-13
云中舞步 2020-11-12
要啥自行车一把梭 2020-11-12
kuwoyinlehe 2020-11-12
minerk 2020-11-12
vitasfly 2020-11-12
jazywoo在路上 2020-11-11
敏敏张 2020-11-11