这是报错信息:SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'appointment.ob_order.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
这是错误信息,上面说我们group使用错误和某个地方冲突了(不兼容问题);
原因:
MySQL 5.7.5和up实现了对功能依赖的检测。如果启用了only_full_group_by SQL模式(在默认情况下是这样),那么MySQL就会拒绝选择列表、条件或顺序列表引用的查询,这些查询将引用组中未命名的非聚合列,而不是在功能上依赖于它们。(在5.7.5之前,MySQL没有检测到功能依赖项,only_full_group_by在默认情况下是不启用的。关于前5.7.5行为的描述,请参阅MySQL 5.6参考手册。)
解决:
打开mysql配置文件,在[mysqld]下添加如下一行:sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,保存重启就好
文件在phpstudy里面配置可找到(我的是8.0)
执行上面之后我们呢的去重操作就可以使用了
Distinct(true)->field('descriprion') 这两个方法了这只限于字段类型为int时候才可以使用,所以我们可以进行转换格式
去重的两种方式
$all = Db::name( 'order' )->group('id')->order('id desc')->select();//方法一
$all = Db::name( 'order' )->Distinct(true)->field('id')->order('id desc')->select();//方法二
字符串转为整形
<?php
$foo
=
"1"
;
// $foo 是字符串类型
$bar
= (int)
$foo
;
// $bar 是整型
?>