关于mysql启用严格模式问题

https://pan.baidu.com/s/1JWSu5SIxRfv9D4VtGrZMDA 这是数据表的数据   密码:pwsw

在mysql5.7

select * from 
(SELECT * from vinston_unit_practice where `u_id` = 12 AND `status` = 1 AND `first_id` = 205 and update_time  is not null  order by update_time desc) vin
GROUP BY exercise_design_id

在mysql5.5也输入此语句,得到的结果集是不一样的。

我需要的是5.5出来的结果集,查了很久。

在mysql输入  

select @@sql_mode

5.7

STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION

5.5

NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

查了一下,是因为5.7启用了  STRICT_TRANS_TABLES(存储引擎启用严格模式,非法数据值被拒绝)。

所以导致了数据出现不同,因为我这条语句出现的结果导致了引擎不知道拿哪条,所以默认拿第一条。

解决方案:

扫描二维码关注公众号,回复: 5026302 查看本文章

我将sql语句改了

select * from vinston_unit_practice where update_time in
(select update_time from
     (select exercise_design_id,max(update_time) update_time from vinston_unit_practice where  `u_id` = 12 AND `status` = 1 AND `first_id` = 205 group by exercise_design_id ) a)

或者在5.7里面,将此模式换为

NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

此方法,我没有尝试,但是这个方法认为可行

猜你喜欢

转载自blog.csdn.net/qq_31164125/article/details/82500830